cshuo commented on code in PR #13498:
URL: https://github.com/apache/hudi/pull/13498#discussion_r2191868211


##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/PartialUpdateStrategy.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.common.table.read;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.PartialUpdateMode;
+import org.apache.hudi.common.util.StringUtils;
+
+import org.apache.avro.Schema;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.hudi.common.model.HoodieRecord.HOODIE_META_COLUMNS_NAME_TO_POS;
+import static 
org.apache.hudi.common.table.HoodieTableConfig.PARTIAL_UPDATE_CUSTOM_MARKER;
+
+public class PartialUpdateStrategy<T> {
+  private final HoodieReaderContext<T> readerContext;
+  private final PartialUpdateMode partialUpdateMode;
+  private Map<String, String> partialUpdateProperties;
+
+  public PartialUpdateStrategy(HoodieReaderContext<T> readerContext,
+                               PartialUpdateMode partialUpdateMode,
+                               TypedProperties props) {
+    this.readerContext = readerContext;
+    this.partialUpdateMode = partialUpdateMode;
+    this.partialUpdateProperties = parsePartialUpdateProperties(props);
+  }
+
+  /**
+   * Merge records based on partial update mode.
+   * Note that {@param newRecord} refers to the record with higher commit time 
if COMMIT_TIME_ORDERING mode is used,
+   * or higher event time if EVENT_TIME_ORDERING mode us used.
+   */
+  BufferedRecord<T> reconcileFieldsWithOldRecord(BufferedRecord<T> newRecord,
+                                                 BufferedRecord<T> oldRecord,
+                                                 Schema newSchema,
+                                                 Schema oldSchema,
+                                                 boolean 
keepOldMetadataColumns) {
+    // Note that: When either newRecord or oldRecord is a delete record,
+    //            skip partial update since delete records do not have 
meaningful columns.
+    if (partialUpdateMode == PartialUpdateMode.NONE
+        || null == oldRecord
+        || newRecord.isDelete()
+        || oldRecord.isDelete()) {
+      return newRecord;
+    }
+
+    switch (partialUpdateMode) {
+      case KEEP_VALUES:
+      case FILL_DEFAULTS:
+        return newRecord;

Review Comment:
   The description of `KEEP_VALUES` is saying pick value from previous version 
of the record if column value is missing, but here `newRecord` is returned 
directly, is this the expected behavior?
   



##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/PartialUpdateStrategy.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.common.table.read;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.PartialUpdateMode;
+import org.apache.hudi.common.util.StringUtils;
+
+import org.apache.avro.Schema;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.hudi.common.model.HoodieRecord.HOODIE_META_COLUMNS_NAME_TO_POS;
+import static 
org.apache.hudi.common.table.HoodieTableConfig.PARTIAL_UPDATE_CUSTOM_MARKER;
+
+public class PartialUpdateStrategy<T> {
+  private final HoodieReaderContext<T> readerContext;
+  private final PartialUpdateMode partialUpdateMode;
+  private Map<String, String> partialUpdateProperties;
+
+  public PartialUpdateStrategy(HoodieReaderContext<T> readerContext,
+                               PartialUpdateMode partialUpdateMode,
+                               TypedProperties props) {
+    this.readerContext = readerContext;
+    this.partialUpdateMode = partialUpdateMode;
+    this.partialUpdateProperties = parsePartialUpdateProperties(props);
+  }
+
+  /**
+   * Merge records based on partial update mode.
+   * Note that {@param newRecord} refers to the record with higher commit time 
if COMMIT_TIME_ORDERING mode is used,
+   * or higher event time if EVENT_TIME_ORDERING mode us used.
+   */
+  BufferedRecord<T> reconcileFieldsWithOldRecord(BufferedRecord<T> newRecord,
+                                                 BufferedRecord<T> oldRecord,
+                                                 Schema newSchema,
+                                                 Schema oldSchema,
+                                                 boolean 
keepOldMetadataColumns) {
+    // Note that: When either newRecord or oldRecord is a delete record,
+    //            skip partial update since delete records do not have 
meaningful columns.
+    if (partialUpdateMode == PartialUpdateMode.NONE
+        || null == oldRecord
+        || newRecord.isDelete()
+        || oldRecord.isDelete()) {
+      return newRecord;
+    }
+
+    switch (partialUpdateMode) {
+      case KEEP_VALUES:
+      case FILL_DEFAULTS:
+        return newRecord;
+      case IGNORE_DEFAULTS:
+        return reconcileDefaultValues(
+            newRecord, oldRecord, newSchema, oldSchema, 
keepOldMetadataColumns);
+      case IGNORE_MARKERS:
+        return reconcileMarkerValues(
+            newRecord, oldRecord, newSchema, oldSchema);
+      default:
+        return newRecord;
+    }
+  }
+
+  /**
+   * @param newRecord              The newer record determined by the merge 
mode.
+   * @param oldRecord              The older record determined by the merge 
mode.
+   * @param newSchema              The schema of the newer record.
+   * @param oldSchema              The schema of the older record.
+   * @param keepOldMetadataColumns Keep the metadata columns from the older 
record.
+   * @return
+   */
+  BufferedRecord<T> reconcileDefaultValues(BufferedRecord<T> newRecord,

Review Comment:
   nit: refine doc here.



##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/PartialUpdateStrategy.java:
##########
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hudi.common.table.read;
+
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.engine.HoodieReaderContext;
+import org.apache.hudi.common.table.HoodieTableConfig;
+import org.apache.hudi.common.table.PartialUpdateMode;
+import org.apache.hudi.common.util.StringUtils;
+
+import org.apache.avro.Schema;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.hudi.common.model.HoodieRecord.HOODIE_META_COLUMNS_NAME_TO_POS;
+import static 
org.apache.hudi.common.table.HoodieTableConfig.PARTIAL_UPDATE_CUSTOM_MARKER;
+
+public class PartialUpdateStrategy<T> {
+  private final HoodieReaderContext<T> readerContext;
+  private final PartialUpdateMode partialUpdateMode;
+  private Map<String, String> partialUpdateProperties;

Review Comment:
   can be final



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