yihua commented on code in PR #10591:
URL: https://github.com/apache/hudi/pull/10591#discussion_r1569152051


##########
hudi-common/src/main/java/org/apache/hudi/common/fs/FSUtils.java:
##########
@@ -471,22 +541,44 @@ public static FileStatus[] 
getAllDataFilesInPartition(FileSystem fs, Path partit
     }
   }
 
+  public static List<HoodieFileStatus> 
getAllDataFilesInPartition(HoodieStorage storage,
+                                                                  
HoodieLocation partitionPath)
+      throws IOException {
+    final Set<String> validFileExtensions = 
Arrays.stream(HoodieFileFormat.values())
+        
.map(HoodieFileFormat::getFileExtension).collect(Collectors.toCollection(HashSet::new));
+    final String logFileExtension = 
HoodieFileFormat.HOODIE_LOG.getFileExtension();
+
+    try {
+      return storage.listDirectEntries(partitionPath, path -> {
+        String extension = FSUtils.getFileExtension(path.getName());
+        return validFileExtensions.contains(extension) || 
path.getName().contains(logFileExtension);
+      
}).stream().filter(HoodieFileStatus::isFile).collect(Collectors.toList());
+    } catch (IOException e) {
+      // return empty FileStatus if partition does not exist already
+      if (!storage.exists(partitionPath)) {
+        return Collections.emptyList();
+      } else {
+        throw e;
+      }
+    }
+  }
+
   /**
    * Get the latest log file for the passed in file-id in the partition path
    */
-  public static Option<HoodieLogFile> getLatestLogFile(FileSystem fs, Path 
partitionPath, String fileId,
+  public static Option<HoodieLogFile> getLatestLogFile(HoodieStorage storage, 
HoodieLocation partitionPath, String fileId,
                                                        String 
logFileExtension, String deltaCommitTime) throws IOException {
-    return getLatestLogFile(getAllLogFiles(fs, partitionPath, fileId, 
logFileExtension, deltaCommitTime));
+    return getLatestLogFile(getAllLogFiles(storage, partitionPath, fileId, 
logFileExtension, deltaCommitTime));
   }
 
   /**
    * Get all the log files for the passed in file-id in the partition path.
    */
-  public static Stream<HoodieLogFile> getAllLogFiles(FileSystem fs, Path 
partitionPath, final String fileId,
+  public static Stream<HoodieLogFile> getAllLogFiles(HoodieStorage storage, 
HoodieLocation partitionPath, final String fileId,
       final String logFileExtension, final String deltaCommitTime) throws 
IOException {
     try {
-      PathFilter pathFilter = path -> path.getName().startsWith("." + fileId) 
&& path.getName().contains(logFileExtension);
-      return Arrays.stream(fs.listStatus(partitionPath, pathFilter))
+      HoodieLocationFilter pathFilter = path -> path.getName().startsWith("." 
+ fileId) && path.getName().contains(logFileExtension);

Review Comment:
   Fixed in #10672



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to