diff --git a/hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java b/hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java index dc6fc47b5..18e3ee35a 100644 --- a/hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java +++ b/hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java @@ -185,7 +185,11 @@ public abstract class AbstractTableFileSystemView implements SyncableFileSystemV String fileId = pair.getValue(); HoodieFileGroup group = new HoodieFileGroup(pair.getKey(), fileId, timeline); if (baseFiles.containsKey(pair)) { - baseFiles.get(pair).forEach(group::addBaseFile); + // if there are multiple files under the same partition path and file ID, sort them according to the + // modification time of the files to avoid reading the files that failed to write before. + List partitionFileIdPairBaseFiles = baseFiles.get(pair); + partitionFileIdPairBaseFiles.sort(Comparator.comparingLong(o -> o.getFileStatus().getModificationTime())); + partitionFileIdPairBaseFiles.forEach(group::addBaseFile); } if (logFiles.containsKey(pair)) { logFiles.get(pair).forEach(group::addLogFile);