diff --git a/extensions/parquet/table/src/main/java/io/deephaven/parquet/table/ParquetTools.java b/extensions/parquet/table/src/main/java/io/deephaven/parquet/table/ParquetTools.java index 8879c14136d..fb2084e51a3 100644 --- a/extensions/parquet/table/src/main/java/io/deephaven/parquet/table/ParquetTools.java +++ b/extensions/parquet/table/src/main/java/io/deephaven/parquet/table/ParquetTools.java @@ -51,6 +51,7 @@ import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; +import java.util.stream.StreamSupport; import static io.deephaven.parquet.table.ParquetTableWriter.PARQUET_FILE_EXTENSION; import static io.deephaven.util.type.TypeUtils.getUnboxedTypeIfBoxed; @@ -594,15 +595,14 @@ private static Table readTableInternal( final Path firstEntryPath; // Ignore dot files while looking for the first entry try (final DirectoryStream sourceStream = - Files.newDirectoryStream(sourcePath, (path) -> { - final String filename = path.getFileName().toString(); - return !filename.isEmpty() && filename.charAt(0) != '.'; - })) { - final Iterator entryIterator = sourceStream.iterator(); - if (!entryIterator.hasNext()) { + Files.newDirectoryStream(sourcePath, ParquetTools::ignoreDotFiles)) { + // Lexicographical comparison + firstEntryPath = StreamSupport.stream(sourceStream.spliterator(), false) + .min(Path::compareTo) + .orElse(null); + if (firstEntryPath == null) { throw new TableDataException("Source directory " + source + " is empty"); } - firstEntryPath = entryIterator.next(); } catch (IOException e) { throw new TableDataException("Error reading source directory " + source, e); } @@ -619,6 +619,11 @@ private static Table readTableInternal( throw new TableDataException("Source " + source + " is neither a directory nor a regular file"); } + private static boolean ignoreDotFiles(Path path) { + final String filename = path.getFileName().toString(); + return !filename.isEmpty() && filename.charAt(0) != '.'; + } + private static BasicFileAttributes readAttributes(@NotNull final Path path) { try { return Files.readAttributes(path, BasicFileAttributes.class);