lincoln-lil commented on code in PR #21683: URL: https://github.com/apache/flink/pull/21683#discussion_r1073281001
########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/analyze/NonDeterministicUpdateAnalyzer.java: ########## @@ -0,0 +1,80 @@ +/* + * 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.planner.analyze; + +import org.apache.flink.annotation.Internal; +import org.apache.flink.table.api.TableException; +import org.apache.flink.table.api.config.OptimizerConfigOptions; +import org.apache.flink.table.planner.plan.nodes.FlinkRelNode; +import org.apache.flink.table.planner.plan.nodes.physical.stream.StreamPhysicalRel; +import org.apache.flink.table.planner.plan.optimize.StreamNonDeterministicUpdatePlanVisitor; +import org.apache.flink.table.planner.utils.ShortcutUtils; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * An implementation of {@link PlanAnalyzer} to analyze the potential risk of non-deterministic + * update when {@link OptimizerConfigOptions#TABLE_OPTIMIZER_NONDETERMINISTIC_UPDATE_STRATEGY} is + * ignored. + */ +@Internal +public class NonDeterministicUpdateAnalyzer implements PlanAnalyzer { + + public static final NonDeterministicUpdateAnalyzer INSTANCE = + new NonDeterministicUpdateAnalyzer(); + + private static final StreamNonDeterministicUpdatePlanVisitor NDU_VISITOR = + new StreamNonDeterministicUpdatePlanVisitor(); + + private NonDeterministicUpdateAnalyzer() {} + + @Override + public Optional<AnalyzedResult> analyze(FlinkRelNode rel) { + boolean ignoreNDU = + ShortcutUtils.unwrapTableConfig(rel) + .get( + OptimizerConfigOptions + .TABLE_OPTIMIZER_NONDETERMINISTIC_UPDATE_STRATEGY) + == OptimizerConfigOptions.NonDeterministicUpdateStrategy.IGNORE; + if (rel instanceof StreamPhysicalRel && ignoreNDU) { + try { + NDU_VISITOR.visit((StreamPhysicalRel) rel); Review Comment: The plan maybe updated after visit done when there's some lookup join matched the condition. So we'd better to also check the plan if it contains a lookup join which enables `upsertMaterialize`. The case `NonDeterministicDagTest#testCdcJoinDimWithPkOutputNoPkSinkWithoutPk` can be referred as an example adding to your test. -- 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]
