SteNicholas commented on code in PR #594: URL: https://github.com/apache/flink-table-store/pull/594#discussion_r1134691216
########## flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/compact/LookupChangelogMergeFunctionWrapper.java: ########## @@ -0,0 +1,142 @@ +/* + * 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.flink.table.store.file.mergetree.compact; + +import org.apache.flink.table.store.data.InternalRow; +import org.apache.flink.table.store.file.KeyValue; +import org.apache.flink.table.store.types.RowKind; + +import java.util.function.Function; + +import static org.apache.flink.table.store.utils.Preconditions.checkArgument; + +/** + * Wrapper for {@link MergeFunction}s to produce changelog by lookup during the compaction involving + * level 0 files. + * + * <p>Changelog records are generated in the process of the level-0 file participating in the + * compaction, if during the compaction processing: + * + * <ul> + * <li>Without level-0 records, no changelog. + * <li>With level-0 record, with level-x (x > 0) record, level-x record should be BEFORE, level-0 + * should be AFTER. + * <li>With level-0 record, without level-x record, need to lookup the history value of the upper + * level as BEFORE. + * </ul> + */ +public class LookupChangelogMergeFunctionWrapper implements MergeFunctionWrapper<ChangelogResult> { + + private final LookupMergeFunction mergeFunction; + private final MergeFunction<KeyValue> mergeFunction2; + private final Function<InternalRow, KeyValue> lookup; + + private final ChangelogResult reusedResult = new ChangelogResult(); + private final KeyValue reusedBefore = new KeyValue(); + private final KeyValue reusedAfter = new KeyValue(); + + public LookupChangelogMergeFunctionWrapper( + MergeFunctionFactory<KeyValue> mergeFunctionFactory, + Function<InternalRow, KeyValue> lookup) { + MergeFunction<KeyValue> mergeFunction = mergeFunctionFactory.create(); + checkArgument( + mergeFunction instanceof LookupMergeFunction, + "Merge function should be a LookupMergeFunction, but is %s, there is a bug.", Review Comment: ```suggestion "Merge function should be a LookupMergeFunction, but is %s, there is a bug.", ``` -- 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]
