cshuo commented on code in PR #13498:
URL: https://github.com/apache/hudi/pull/13498#discussion_r2191332536
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/HoodieFileGroupReader.java:
##########
@@ -127,6 +129,7 @@ private HoodieFileGroupReader(HoodieReaderContext<T>
readerContext, HoodieStorag
HoodieTableConfig tableConfig = hoodieTableMetaClient.getTableConfig();
this.partitionPath = fileSlice.getPartitionPath();
this.partitionPathFields = tableConfig.getPartitionFields();
+ this.partialUpdateMode = tableConfig.getPartialUpdateMode();
Review Comment:
can be local variable.
##########
hudi-common/src/main/java/org/apache/hudi/common/table/read/BufferedRecordMergerFactory.java:
##########
@@ -98,12 +122,28 @@ public Pair<Boolean, T> finalMerge(BufferedRecord<T>
olderRecord, BufferedRecord
* based on {@code EVENT_TIME_ORDERING} merge mode.
*/
private static class EventTimeBufferedRecordMerger<T> implements
BufferedRecordMerger<T> {
+ private final PartialUpdateStrategy<T> partialUpdateStrategy;
+ private final Schema readerSchema;
+
+ public EventTimeBufferedRecordMerger(HoodieReaderContext<T> readerContext,
+ PartialUpdateMode partialUpdateMode,
+ TypedProperties props,
+ Schema readerSchema) {
+ this.partialUpdateStrategy = new PartialUpdateStrategy<>(readerContext,
partialUpdateMode, props);
+ this.readerSchema = readerSchema;
+ }
+
@Override
public Option<BufferedRecord<T>> deltaMerge(BufferedRecord<T> newRecord,
BufferedRecord<T> existingRecord) {
if (existingRecord == null || shouldKeepNewerRecord(existingRecord,
newRecord)) {
+ newRecord = partialUpdateStrategy.reconcileFieldsWithOldRecord(
+ newRecord, existingRecord, readerSchema, readerSchema, false);
return Option.of(newRecord);
+ } else {
+ existingRecord = partialUpdateStrategy.reconcileFieldsWithOldRecord(
Review Comment:
Here may introduce performance regression. It
seems`reconcileFieldsWithOldRecord` never return null, so now `deltaMerge`
never return empty, while previously we use empty option to skip updating the
record buffer. We should align the behavior when partial update mode is None.
##########
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:
same as the below default branch.
--
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]