fengjian428 commented on code in PR #4676:
URL: https://github.com/apache/hudi/pull/4676#discussion_r973032219


##########
hudi-common/src/main/java/org/apache/hudi/common/model/OverwriteNonDefaultsWithLatestAvroPayload.java:
##########
@@ -58,19 +58,32 @@ public Option<IndexedRecord> 
combineAndGetUpdateValue(IndexedRecord currentValue
     GenericRecord insertRecord = (GenericRecord) recordOption.get();
     GenericRecord currentRecord = (GenericRecord) currentValue;
 
-    if (isDeleteRecord(insertRecord)) {
+    return mergeRecords(schema, insertRecord, currentRecord);
+  }
+
+  /**
+   * Merges the given records into one.
+   *
+   * @param schema       The record schema
+   * @param baseRecord   The base record to merge with
+   * @param mergedRecord The record to be merged
+   *
+   * @return the merged record option
+   */
+  protected Option<IndexedRecord> mergeRecords(Schema schema, GenericRecord 
baseRecord, GenericRecord mergedRecord) {
+    if (isDeleteRecord(baseRecord)) {
       return Option.empty();
     } else {
       final GenericRecordBuilder builder = new GenericRecordBuilder(schema);
       List<Schema.Field> fields = schema.getFields();
       fields.forEach(field -> {
-        Object value = insertRecord.get(field.name());
+        Object value = baseRecord.get(field.name());
         value = field.schema().getType().equals(Schema.Type.STRING) && value 
!= null ? value.toString() : value;
         Object defaultValue = field.defaultVal();
         if (!overwriteField(value, defaultValue)) {
           builder.set(field, value);
         } else {
-          builder.set(field, currentRecord.get(field.pos()));
+          builder.set(field, mergedRecord.get(field.pos()));
         }

Review Comment:
   > TestOverwriteNonDefaultsWithLatestAvroPayload
   
   done~



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