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/03/04 08:14:57 UTC

[GitHub] [hudi] danny0405 commented on a diff in pull request #7687: [HUDI-5606] Update to handle deletes in postgres debezium

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


##########
hudi-common/src/main/java/org/apache/hudi/common/model/debezium/AbstractDebeziumAvroPayload.java:
##########
@@ -55,19 +55,26 @@ public AbstractDebeziumAvroPayload(Option<GenericRecord> record) {
 
   @Override
   public Option<IndexedRecord> getInsertValue(Schema schema) throws IOException {
-    IndexedRecord insertRecord = getInsertRecord(schema);
-    return handleDeleteOperation(insertRecord);
+    Option<IndexedRecord> insertRecord = getInsertRecord(schema);
+    if (!insertRecord.isPresent()) {
+      return insertRecord;
+    }
+    return handleDeleteOperation(insertRecord.get());
   }
 
   @Override
   public Option<IndexedRecord> combineAndGetUpdateValue(IndexedRecord currentValue, Schema schema) throws IOException {
     // Step 1: If the time occurrence of the current record in storage is higher than the time occurrence of the
     // insert record (including a delete record), pick the current record.
-    if (shouldPickCurrentRecord(currentValue, getInsertRecord(schema), schema)) {
-      return Option.of(currentValue);
+    Option<IndexedRecord> indexedRecordOption = getInsertValue(schema);
+    if (indexedRecordOption.isPresent()) {
+      if (shouldPickCurrentRecord(currentValue, getInsertRecord(schema).get(), schema)) {
+        return Option.of(currentValue);
+      }
+      // Step 2: Pick the insert record (as a delete record if its a deleted event)
+      return getInsertValue(schema);

Review Comment:
   No need to invoke `getInsertValue(schema);` twice, can fallback to line 77 directly.



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