voonhous commented on code in PR #20846:
URL: https://github.com/apache/hudi/pull/20846#discussion_r4707368071


##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/index/HoodieIndexUtils.java:
##########
@@ -464,6 +467,46 @@ private static <R> Option<HoodieRecord<R>> 
mergeIncomingWithExistingRecord(
     }
   }
 
+  /**
+   * Keeps one incoming record per record key of the ones that wait for a 
merged lookup, as
+   * {@link HoodieData#distinctWithKey} does, and fails with a {@link 
HoodieMultipleMatchesException} when more than one
+   * incoming record matches one row. The index pairs every incoming record 
with each row it locates the key at, and
+   * the rows of a key differ in file group or position, so more than one 
incoming record shows as more than one pair
+   * for a row, while one record located at several rows does not fail. The 
incoming records the index already tagged
+   * count as well, as one of them and one that waits for the merged lookup 
can match the same row. See
+   * {@link HoodieWriteConfig#UPSERT_FAIL_ON_MULTIPLE_MATCHES}.
+   */
+  private static <R> HoodieData<HoodieRecord<R>> 
distinctLocatedRecordsFailingOnMultipleMatches(
+      HoodieData<Pair<HoodieRecord<R>, Option<HoodieRecordGlobalLocation>>> 
incomingRecordsAndLocations, int parallelism) {
+    return incomingRecordsAndLocations
+        .filter(p -> p.getRight().isPresent() || 
p.getLeft().isCurrentLocationKnown())

Review Comment:
   **blocker:** With a global index on MOR, the matches are counted on the raw 
located pairs, before `getExistingRecords`. After `delete from t where id = 1` 
(log-file delete), two source rows for id 1 would raise a violation, although 
the existing-record join below then finds no record and tags them as new 
("existing record not found"). I traced this and have not run it. Could the 
count move after the existing-record join, with a two-source-row variant of the 
test at `TestMergeIntoCardinalityCheck.scala:342`?



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