diff --git a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileIterator.java b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileIterator.java index 23e33ec6b3b2..906395aa92d1 100644 --- a/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileIterator.java +++ b/lib/trino-filesystem/src/main/java/io/trino/filesystem/local/LocalFileIterator.java @@ -46,15 +46,29 @@ public LocalFileIterator(Location location, Path rootPath, Path path, boolean is this.iterator = emptyIterator(); } else { - try (Stream stream = (isRecursive ? Files.walk(path) : Files.list(path))) { - this.iterator = stream - .filter(Files::isRegularFile) - // materialize full list so stream can be closed - .collect(toImmutableList()) - .iterator(); + if (isRecursive) { + try (Stream stream = Files.walk(path)) { + this.iterator = stream + .filter(Files::isRegularFile) + // materialize full list so stream can be closed + .collect(toImmutableList()) + .iterator(); + } + catch (IOException e) { + throw handleException(location, e); + } } - catch (IOException e) { - throw handleException(location, e); + else { + try (Stream stream = Files.list(path)) { + this.iterator = stream + .filter(Files::isRegularFile) + // materialize full list so stream can be closed + .collect(toImmutableList()) + .iterator(); + } + catch (IOException e) { + throw handleException(location, e); + } } } } diff --git a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/table/HudiTableFileSystemView.java b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/table/HudiTableFileSystemView.java index 533b1470116b..76117f9138cd 100644 --- a/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/table/HudiTableFileSystemView.java +++ b/plugin/trino-hudi/src/main/java/io/trino/plugin/hudi/table/HudiTableFileSystemView.java @@ -40,7 +40,6 @@ import org.apache.avro.specific.SpecificRecordBase; import java.io.IOException; -import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet;