You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "danny0405 (via GitHub)" <gi...@apache.org> on 2023/02/03 07:28:44 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #7281: [HUDI-5270] Duplicate key error when insert_overwrite same partition …

danny0405 commented on code in PR #7281:
URL: https://github.com/apache/hudi/pull/7281#discussion_r1095433428


##########
hudi-common/src/main/java/org/apache/hudi/common/table/view/AbstractTableFileSystemView.java:
##########
@@ -244,7 +244,9 @@ private void resetFileGroupsReplaced(HoodieTimeline timeline) {
       }
     });
 
-    Map<HoodieFileGroupId, HoodieInstant> replacedFileGroups = resultStream.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
+    // Duplicate key error when insert_overwrite same partition in multi writer, distinct HoodieFileGroupId,If repeated, save instant with the larger timestamp
+    Map<HoodieFileGroupId, HoodieInstant> replacedFileGroups = resultStream.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
+            (instance1, instance2) -> instance1.compareTo(instance2) < 0 ? instance2 : instance1));
     resetReplacedFileGroups(replacedFileGroups);

Review Comment:
   It is better to use `HoodieTimeline.compareTimestamps` for comparing the instants..



-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org