xushiyan commented on code in PR #8490:
URL: https://github.com/apache/hudi/pull/8490#discussion_r1185840597
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/index/simple/HoodieGlobalSimpleIndex.java:
##########
@@ -113,42 +114,47 @@ protected List<Pair<String, HoodieBaseFile>>
getAllBaseFilesInTable(
* @param existingRecords existing records with {@link HoodieRecordLocation}s
* @return {@link HoodieData} of {@link HoodieRecord}s with tagged {@link
HoodieRecordLocation}s
*/
- private <R> HoodieData<HoodieRecord<R>> getTaggedRecords(
+ @VisibleForTesting
+ <R> HoodieData<HoodieRecord<R>> getTaggedRecords(
HoodiePairData<String, HoodieRecord<R>> incomingRecords,
- HoodiePairData<HoodieKey, HoodieRecordLocation> existingRecords) {
+ HoodiePairData<HoodieKey, HoodieRecordLocation> existingRecords,
+ HoodieTable hoodieTable) {
HoodiePairData<String, Pair<String, HoodieRecordLocation>>
existingRecordByRecordKey =
existingRecords.mapToPair(
entry -> new ImmutablePair<>(entry.getLeft().getRecordKey(),
Pair.of(entry.getLeft().getPartitionPath(),
entry.getRight())));
- return incomingRecords.leftOuterJoin(existingRecordByRecordKey).values()
- .flatMap(entry -> {
+ // Pair of a tagged record and the partition+location if tagged
+ HoodieData<Pair<HoodieRecord<R>, Option<Pair<String,
HoodieRecordLocation>>>> taggedRecordsAndLocationInfo =
incomingRecords.leftOuterJoin(existingRecordByRecordKey).values()
+ .map(entry -> {
HoodieRecord<R> inputRecord = entry.getLeft();
Option<Pair<String, HoodieRecordLocation>> partitionPathLocationPair
= Option.ofNullable(entry.getRight().orElse(null));
- List<HoodieRecord<R>> taggedRecords;
-
if (partitionPathLocationPair.isPresent()) {
String partitionPath = partitionPathLocationPair.get().getKey();
HoodieRecordLocation location =
partitionPathLocationPair.get().getRight();
- if (config.getGlobalSimpleIndexUpdatePartitionPath() &&
!(inputRecord.getPartitionPath().equals(partitionPath))) {
- // Create an empty record to delete the record in the old
partition
- HoodieRecord<R> deleteRecord = new HoodieAvroRecord(new
HoodieKey(inputRecord.getRecordKey(), partitionPath), new
EmptyHoodieRecordPayload());
- deleteRecord.setCurrentLocation(location);
- deleteRecord.seal();
- // Tag the incoming record for inserting to the new partition
- HoodieRecord<R> insertRecord = (HoodieRecord<R>)
HoodieIndexUtils.getTaggedRecord(inputRecord, Option.empty());
- taggedRecords = Arrays.asList(deleteRecord, insertRecord);
+ if (config.getGlobalSimpleIndexUpdatePartitionPath()) {
+ // The incoming record may need to be inserted to a new
partition; keep the location info for merging later.
+ return Pair.of(inputRecord, partitionPathLocationPair);
} else {
// Ignore the incoming record's partition, regardless of whether
it differs from its old partition or not.
// When it differs, the record will still be updated at its old
partition.
HoodieRecord<R> newRecord = new HoodieAvroRecord(new
HoodieKey(inputRecord.getRecordKey(), partitionPath), (HoodieRecordPayload)
inputRecord.getData());
- taggedRecords = Collections.singletonList((HoodieRecord<R>)
HoodieIndexUtils.getTaggedRecord(newRecord, Option.ofNullable(location)));
+ return Pair.of(HoodieIndexUtils.getTaggedRecord(newRecord,
Option.of(location)), Option.empty());
}
} else {
- taggedRecords = Collections.singletonList((HoodieRecord<R>)
HoodieIndexUtils.getTaggedRecord(inputRecord, Option.empty()));
+ return Pair.of(HoodieIndexUtils.getTaggedRecord(inputRecord,
Option.empty()), Option.empty());
}
- return taggedRecords.iterator();
});
+
+ if (config.getSimpleIndexUseCaching()) {
+ taggedRecordsAndLocationInfo.persist(new HoodieConfig(config.getProps())
+
.getString(HoodieIndexConfig.SIMPLE_INDEX_INPUT_STORAGE_LEVEL_VALUE));
+ }
+ HoodieData<HoodieRecord<R>> finalTaggedRecords =
mergeForPartitionUpdates(taggedRecordsAndLocationInfo, config, hoodieTable);
Review Comment:
good catch. fixed!
--
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]