nsivabalan commented on code in PR #7429:
URL: https://github.com/apache/hudi/pull/7429#discussion_r1054551194


##########
hudi-common/src/main/java/org/apache/hudi/metadata/HoodieTableMetadataUtil.java:
##########
@@ -967,6 +974,96 @@ public static HoodieData<HoodieRecord> 
convertFilesToColumnStatsRecords(HoodieEn
     return allRecordsRDD;
   }
 
+  /**
+   * Convert added and deleted action metadata to record level index index 
records.
+   */
+  public static HoodieData<HoodieRecord> 
convertFilesToRecordLevelIndex(HoodieEngineContext engineContext,
+                                                                        
Map<String, List<String>> partitionToDeletedFiles,
+                                                                        
Map<String, Map<String, Long>> partitionToAppendedFiles,
+                                                                        
MetadataRecordsGenerationParams recordsGenerationParams,
+                                                                        String 
instantTime,
+                                                                        String 
datasetBasePath,
+                                                                        
Option<BaseKeyGenerator> keyGeneratorOpt) {
+    HoodieData<HoodieRecord> allRecordsRDD = engineContext.emptyHoodieData();
+
+    List<Pair<String, List<String>>> partitionToDeletedFilesList = 
partitionToDeletedFiles.entrySet()
+        .stream().map(e -> Pair.of(e.getKey(), 
e.getValue())).collect(Collectors.toList());
+    List<Pair<String, String>> filesToDelete = 
partitionToDeletedFilesList.stream().flatMap(e -> e.getRight().stream().map(f 
-> Pair.of(e.getLeft(), f))).collect(Collectors.toList());
+    int parallelism = Math.max(Math.min(filesToDelete.size(), 
recordsGenerationParams.getRecordLevelIndexParallelism()), 1);
+    HoodieData<Pair<String, String>> partitionToDeletedFilesRDD = 
engineContext.parallelize(filesToDelete, parallelism);
+
+    HoodieData<HoodieRecord> deletedFilesRecordsRDD = 
partitionToDeletedFilesRDD.filter(p -> FSUtils.isBaseFile(new 
Path(p.getRight()))).flatMap(partitionToDeletedFilePair -> {
+      return getRecordIndexFromParquetFile(new Configuration(), 
datasetBasePath, partitionToDeletedFilePair, true, keyGeneratorOpt);
+    });
+    allRecordsRDD = allRecordsRDD.union(deletedFilesRecordsRDD);
+
+    List<Pair<String, Map<String, Long>>> partitionToAppendedFilesList = 
partitionToAppendedFiles.entrySet()
+        .stream().map(entry -> Pair.of(entry.getKey(), 
entry.getValue())).collect(Collectors.toList());
+    List<Pair<String, String>> filesToAppended = 
partitionToAppendedFilesList.stream().flatMap(e -> 
e.getRight().keySet().stream().map(f -> Pair.of(e.getLeft(), 
f))).collect(Collectors.toList());
+    parallelism = Math.max(Math.min(filesToAppended.size(), 
recordsGenerationParams.getRecordLevelIndexParallelism()), 1);
+    HoodieData<Pair<String, String>> partitionToAppendedFilesRDD = 
engineContext.parallelize(filesToAppended, parallelism);
+
+    HoodieData<HoodieRecord> appendedFilesRecordsRDD = 
partitionToAppendedFilesRDD.filter(p -> FSUtils.isBaseFile(new 
Path(p.getRight()))).flatMap(partitionToDeletedFilePair -> {
+      return getRecordIndexFromParquetFile(new Configuration(), 
datasetBasePath, partitionToDeletedFilePair, false, keyGeneratorOpt);
+    });
+
+    allRecordsRDD = allRecordsRDD.union(appendedFilesRecordsRDD);
+
+    return allRecordsRDD;
+  }
+
+  private static Iterator<HoodieRecord> getRecordIndexFromParquetFile(
+      Configuration conf,
+      String datasetBasePath,
+      Pair<String, String> partitionToFilePair,
+      boolean isDeleted,
+      Option<BaseKeyGenerator> keyGeneratorOpt) {
+    final String partition = 
getPartitionIdentifier(partitionToFilePair.getLeft());
+    final String fileName = partitionToFilePair.getRight();
+    final String fileId = FSUtils.getFileId(fileName);
+    final String fileCommitTime = FSUtils.getCommitTime(fileName);
+
+    Path dataFilePath = new Path(datasetBasePath, String.format("%s%s%s", 
partition, Path.SEPARATOR, fileName));
+
+    BaseFileUtils baseFileUtils = 
BaseFileUtils.getInstance(dataFilePath.toString());
+    Iterator<HoodieKey> recordKeyIterator;
+    if (keyGeneratorOpt.isPresent()) {
+      recordKeyIterator = baseFileUtils.getHoodieKeyIterator(conf, 
dataFilePath, keyGeneratorOpt);
+    } else {
+      recordKeyIterator = baseFileUtils.getHoodieKeyIterator(conf, 
dataFilePath);
+    }
+    // final List<Long> blockRecordSize = 
baseFileUtils.getBlockRecordSize(conf, dataFilePath);
+
+    return new Iterator<HoodieRecord>() {
+      long size = 0L;
+
+      @Override
+      public boolean hasNext() {
+        return recordKeyIterator.hasNext();
+      }
+
+      @Override
+      public HoodieRecord next() {
+        size++;
+        // int rowGroupIndex = findRowGroupIndex();
+        int rowGroupIndex = -1;
+        HoodieKey next = recordKeyIterator.next();
+        return 
HoodieMetadataPayload.createRecordLevelIndexRecord(next.getRecordKey(), 
next.getPartitionPath(), fileId, rowGroupIndex, isDeleted, fileCommitTime, 
HoodieOperation.INSERT);
+      }
+
+      // int findRowGroupIndex() {

Review Comment:
   guess its not yet used as of this patch. but w/ hfile, may I know how does 
this row group index help us? 



##########
hudi-common/src/main/avro/HoodieMetadata.avsc:
##########
@@ -358,6 +358,45 @@
                 }
             ],
             "default" : null
+        },
+        {
+            "name": "recordLevelIndexMetadata",
+            "doc": "Contains information about record keys and their location 
in the dataset",
+            "type": [
+                "null",
+                {
+                    "type": "record",
+                    "name": "HoodieMetadataRecordLevelIndex",
+                    "fields": [
+                        {
+                            "name": "partition",
+                            "type": "string",
+                            "doc": "Partition which contains the record",
+                            "avro.java.string": "String"
+                        },
+                        {
+                            "name": "fileId",
+                            "type": "string",
+                            "doc": "FileId of file group"
+                        },
+                        {
+                            "name": "rowGroupIndex",

Review Comment:
   may I know whats the purpose of row group index ? 



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