loukey-lj commented on code in PR #7429:
URL: https://github.com/apache/hudi/pull/7429#discussion_r1058019890
##########
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:
RowGroupIndex a reserved attribute, which indicates the serial number of the
rowGroup in the parquet file, and it has not been collected in this pr.
--
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]