cshuo commented on code in PR #13540: URL: https://github.com/apache/hudi/pull/13540#discussion_r2209093043
########## hudi-common/src/main/java/org/apache/hudi/common/table/read/PartialUpdateStrategy.java: ########## @@ -0,0 +1,221 @@ +/* + * 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.hudi.common.util.collection.Pair; + +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; +import static org.apache.hudi.common.util.ConfigUtils.toMap; + +/** + * This class implements the detailed partial update logic for different partial update modes, + * which is wrapped into partial update mergers + * {@link BufferedRecordMergerFactory.CommitTimeBufferedRecordPartialUpdateMerger} and + * {@link BufferedRecordMergerFactory.EventTimeBufferedRecordPartialUpdateMerger}. + */ +public class PartialUpdateStrategy<T> { + private final HoodieReaderContext<T> readerContext; + private final PartialUpdateMode partialUpdateMode; + private final Map<String, String> mergeProperties; + private final PartialMergingUtils<T> partialMergingUtils; + + public PartialUpdateStrategy(HoodieReaderContext<T> readerContext, + PartialUpdateMode partialUpdateMode, + TypedProperties props) { + this.readerContext = readerContext; + this.partialUpdateMode = partialUpdateMode; + this.mergeProperties = parseMergeProperties(props); + if (partialUpdateMode == PartialUpdateMode.KEEP_VALUES) { + partialMergingUtils = new PartialMergingUtils<>(); + } else { + partialMergingUtils = null; + } + } + + /** + * 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. + */ + Pair<BufferedRecord<T>, Schema> partialMerge(BufferedRecord<T> newRecord, + BufferedRecord<T> oldRecord, + Schema newSchema, + Schema oldSchema, + Schema readerSchema, + boolean keepOldMetadataColumns, + boolean enablePartialMerging) { + // 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 Review Comment: `partialUpdateMode` can not be `PartialUpdateMode.NONE` now, maybe we can add validating check for update mode in the constructor, and remove the check here. -- 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]
