hudi-agent commented on code in PR #18901:
URL: https://github.com/apache/hudi/pull/18901#discussion_r3345307216


##########
hudi-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java:
##########
@@ -175,7 +181,42 @@ public List<HoodieColumnRangeMetadata<Comparable>> 
readColumnStatsFromMetadata(H
                                                                                
   StoragePath filePath,
                                                                                
   List<String> columnList,
                                                                                
   HoodieIndexVersion indexVersion) {
-    throw new UnsupportedOperationException("readColumnStatsFromMetadata is 
not yet supported for Lance format");
+    if (columnList == null || columnList.isEmpty()) {
+      return Collections.emptyList();
+    }
+
+    try (HoodieFileReader fileReader =
+             HoodieIOFactory.getIOFactory(storage)
+                 .getReaderFactory(HoodieRecord.HoodieRecordType.SPARK)
+                 .getFileReader(
+                     ConfigUtils.DEFAULT_HUDI_CONFIG_FOR_READER,
+                     filePath,
+                     HoodieFileFormat.LANCE)) {
+      HoodieSchema fileSchema = fileReader.getSchema();
+      List<Pair<String, HoodieSchemaField>> fieldsToIndex = columnList.stream()
+          .map(columnName -> HoodieSchemaUtils.getNestedField(fileSchema, 
columnName))
+          .filter(Option::isPresent)
+          .map(Option::get)
+          .collect(Collectors.toList());
+      if (fieldsToIndex.isEmpty()) {
+        return Collections.emptyList();
+      }
+
+      List<String> projectedColumns = fieldsToIndex.stream()
+          .map(Pair::getKey)
+          .collect(Collectors.toList());
+      HoodieSchema projectedSchema = 
HoodieSchemaUtils.projectSchema(fileSchema, projectedColumns);
+      try (ClosableIterator<HoodieRecord> recordIterator = 
fileReader.getRecordIterator(projectedSchema)) {
+        Map<String, HoodieColumnRangeMetadata<Comparable>> 
columnRangeMetadataMap =
+            HoodieTableMetadataUtil.collectColumnRangeMetadata(
+                recordIterator, fieldsToIndex, filePath.getName(), 
projectedSchema, storage.getConf(), indexVersion);
+        return fieldsToIndex.stream()
+            .map(field -> columnRangeMetadataMap.get(field.getKey()))
+            .collect(Collectors.toCollection(ArrayList::new));
+      }

Review Comment:
   🤖 nit: could you use `Collectors.toList()` here instead of 
`Collectors.toCollection(ArrayList::new)`? There's no caller contract that 
requires a mutable `ArrayList`, so the more idiomatic form would be cleaner.
   
   <sub><i>- AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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