nsivabalan commented on a change in pull request #1091: [HUDI-389] Fixing Index 
look up to return right partitions for a given key along with fileId with 
Global Bloom
URL: https://github.com/apache/incubator-hudi/pull/1091#discussion_r357501183
 
 

 ##########
 File path: 
hudi-client/src/main/java/org/apache/hudi/index/bloom/HoodieGlobalBloomIndex.java
 ##########
 @@ -98,26 +100,34 @@ public HoodieGlobalBloomIndex(HoodieWriteConfig config) {
       String recordKey = partitionRecordKeyPair._2();
       String partitionPath = partitionRecordKeyPair._1();
 
-      return indexFileFilter.getMatchingFiles(partitionPath, 
recordKey).stream()
-          .map(file -> new Tuple2<>(file, new HoodieKey(recordKey, 
indexToPartitionMap.get(file))))
+      return indexFileFilter.getMatchingFilesAndPartition(partitionPath, 
recordKey).stream()
+          .map(partitionFileIdPair -> new 
Tuple2<>(partitionFileIdPair.getRight(),
+              new HoodieKey(recordKey, partitionFileIdPair.getLeft())))
           .collect(Collectors.toList());
     }).flatMap(List::iterator);
   }
 
-
   /**
    * Tagging for global index should only consider the record key.
    */
   @Override
   protected JavaRDD<HoodieRecord<T>> tagLocationBacktoRecords(
       JavaPairRDD<HoodieKey, HoodieRecordLocation> keyFilenamePairRDD, 
JavaRDD<HoodieRecord<T>> recordRDD) {
-    JavaPairRDD<String, HoodieRecord<T>> rowKeyRecordPairRDD =
-        recordRDD.mapToPair(record -> new Tuple2<>(record.getRecordKey(), 
record));
 
-    // Here as the recordRDD might have more data than rowKeyRDD (some 
rowKeys' fileId is null),
-    // so we do left outer join.
-    return rowKeyRecordPairRDD.leftOuterJoin(keyFilenamePairRDD.mapToPair(p -> 
new Tuple2<>(p._1.getRecordKey(), p._2)))
-        .values().map(value -> getTaggedRecord(value._1, 
Option.ofNullable(value._2.orNull())));
+    Map<String, Pair<HoodieKey, HoodieRecordLocation>> keyMap = 
keyFilenamePairRDD
+        .mapToPair(e -> new Tuple2<>(e._1.getRecordKey(), Pair.of(e._1, 
e._2))).collectAsMap();
+
+    JavaRDD<HoodieRecord<T>> toReturn = recordRDD.map(rec -> {
+      if (keyMap.containsKey(rec.getRecordKey())) {
+        Pair<HoodieKey, HoodieRecordLocation> value = 
keyMap.get(rec.getRecordKey());
+        return getTaggedRecord(new HoodieRecord(value.getLeft(), 
rec.getData()), Option.of(value
 
 Review comment:
   yes, you are right. keyMap contains existing record key information 
(HoodieKey, HoodieRecordLocation) in existing data set . For each incoming 
record to be upserted, if record key is located already, we need to upsert to 
the same partition even if incoming record (to be updated) was tagged with a 
different partition.And so, we reconstruct the HoodieKey with recordKey from 
incoming record and partition path from keyMap(index look up).
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to