the-other-tim-brown commented on code in PR #13586:
URL: https://github.com/apache/hudi/pull/13586#discussion_r2220756341


##########
hudi-common/src/main/java/org/apache/hudi/common/table/TableSchemaResolver.java:
##########
@@ -459,19 +460,20 @@ private HoodieCommitMetadata 
getCachedCommitMetadata(HoodieInstant instant) {
         });
   }
 
-  private Schema fetchSchemaFromFiles(Iterator<String> filePaths) throws 
IOException {
-    Schema schema = null;
-    while (filePaths.hasNext() && schema == null) {
-      StoragePath filePath = new StoragePath(filePaths.next());
-      if (FSUtils.isLogFile(filePath)) {
-        // this is a log file
-        schema = readSchemaFromLogFile(filePath);
-      } else {
-        schema = HoodieIOFactory.getIOFactory(metaClient.getStorage())
-            
.getFileFormatUtils(filePath).readAvroSchema(metaClient.getStorage(), filePath);
+  private Schema fetchSchemaFromFiles(Stream<StoragePath> filePaths) {
+    return filePaths.map(filePath -> {
+      try {
+        if (FSUtils.isLogFile(filePath)) {
+          // this is a log file
+          return readSchemaFromLogFile(filePath);
+        } else {
+          return HoodieIOFactory.getIOFactory(metaClient.getStorage())
+              
.getFileFormatUtils(filePath).readAvroSchema(metaClient.getStorage(), filePath);
+        }
+      } catch (IOException e) {
+        throw new HoodieIOException("Failed to read schema from file: " + 
filePath, e);
       }
-    }
-    return schema;
+    }).filter(Objects::nonNull).findFirst().orElse(null);

Review Comment:
   If it is a log file with only deletes it will return a null schema



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to