From 8321281001df864134decb5f32914e5d1b344148 Mon Sep 17 00:00:00 2001 From: wyb Date: Fri, 13 Dec 2024 15:42:29 +0800 Subject: [PATCH] [BugFix] Fix list files when no files were found (#53901) Signed-off-by: wyb --- .../com/starrocks/catalog/TableFunctionTable.java | 3 +++ .../java/com/starrocks/fs/hdfs/HdfsFsManager.java | 2 +- test/sql/test_files/R/csv_format | 11 +++++++++++ test/sql/test_files/T/csv_format | 7 +++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/TableFunctionTable.java b/fe/fe-core/src/main/java/com/starrocks/catalog/TableFunctionTable.java index 201875d58be59..06e07be1afec1 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/TableFunctionTable.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/TableFunctionTable.java @@ -241,6 +241,9 @@ public List> listFilesAndDirs() { files.add(fileInfo); } } + if (files.isEmpty()) { + ErrorReport.reportDdlException(ErrorCode.ERR_NO_FILES_FOUND, path); + } return files; } catch (StarRocksException e) { LOG.warn("failed to parse files", e); diff --git a/fe/fe-core/src/main/java/com/starrocks/fs/hdfs/HdfsFsManager.java b/fe/fe-core/src/main/java/com/starrocks/fs/hdfs/HdfsFsManager.java index d162a140c8917..305c8c9ea89e7 100644 --- a/fe/fe-core/src/main/java/com/starrocks/fs/hdfs/HdfsFsManager.java +++ b/fe/fe-core/src/main/java/com/starrocks/fs/hdfs/HdfsFsManager.java @@ -1203,7 +1203,7 @@ public List listFileMeta(String path, Map properties Path pathPattern = new Path(pathUri.getPath()); try { FileStatus[] files = fileSystem.getDFSFileSystem().globStatus(pathPattern); - return Lists.newArrayList(files); + return files != null ? Lists.newArrayList(files) : Lists.newArrayList(); } catch (FileNotFoundException e) { LOG.info("file not found: " + path, e); throw new StarRocksException("file not found: " + path, e); diff --git a/test/sql/test_files/R/csv_format b/test/sql/test_files/R/csv_format index 7927240a744fa..dbbc8e0237470 100644 --- a/test/sql/test_files/R/csv_format +++ b/test/sql/test_files/R/csv_format @@ -73,6 +73,17 @@ select path, size, is_dir from files( "aws.s3.secret_key" = "${oss_sk}", "aws.s3.endpoint" = "${oss_endpoint}"); -- result: +[REGEX].*failed to parse files: No files were found matching the pattern\(s\) or path\(s\).* +-- !result + +select path, size, is_dir from files( + "path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/xxxxxx", + "list_files_only" = "true", + "aws.s3.access_key" = "${oss_ak}", + "aws.s3.secret_key" = "${oss_sk}", + "aws.s3.endpoint" = "${oss_endpoint}"); +-- result: +[REGEX].*failed to parse files: No files were found matching the pattern\(s\) or path\(s\).* -- !result shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/csv_format/${uuid0}/ > /dev/null diff --git a/test/sql/test_files/T/csv_format b/test/sql/test_files/T/csv_format index cb5fa87302d15..631e09325b1c9 100644 --- a/test/sql/test_files/T/csv_format +++ b/test/sql/test_files/T/csv_format @@ -34,5 +34,12 @@ select path, size, is_dir from files( "aws.s3.secret_key" = "${oss_sk}", "aws.s3.endpoint" = "${oss_endpoint}"); +select path, size, is_dir from files( + "path" = "oss://${oss_bucket}/test_files/csv_format/${uuid0}/xxxxxx", + "list_files_only" = "true", + "aws.s3.access_key" = "${oss_ak}", + "aws.s3.secret_key" = "${oss_sk}", + "aws.s3.endpoint" = "${oss_endpoint}"); + -- clean shell: ossutil64 rm -rf oss://${oss_bucket}/test_files/csv_format/${uuid0}/ > /dev/null