puneetdixit200 commented on code in PR #18901:
URL: https://github.com/apache/hudi/pull/18901#discussion_r3348948143
##########
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:
Fixed in 5bab0a000.
##########
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:
Fixed in 5bab0a000.
##########
hudi-common/src/test/java/org/apache/hudi/metadata/TestMetadataPartitionType.java:
##########
@@ -111,6 +112,20 @@ public void
testPartitionEnabledByConfigOnly(MetadataPartitionType partitionType
assertTrue(enabledPartitions.contains(partitionType) ||
MetadataPartitionType.ALL_PARTITIONS.equals(partitionType));
}
+ @Test
+ public void testColumnAndPartitionStatsEnabledForLanceTables() {
+ HoodieTableConfig tableConfig = Mockito.mock(HoodieTableConfig.class);
+
Mockito.when(tableConfig.getBaseFileFormat()).thenReturn(HoodieFileFormat.LANCE);
Review Comment:
Removed in 8c17e31a6.
--
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]