danny0405 commented on code in PR #18901:
URL: https://github.com/apache/hudi/pull/18901#discussion_r3497321433


##########
hudi-common/src/main/java/org/apache/hudi/common/util/LanceUtils.java:
##########
@@ -175,7 +180,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)) {

Review Comment:
   you just read the files again, a more proper way is to collect the column 
stats during the write, we might need to add a hook in base file write to 
trigger the column stats collection.



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