wuchong commented on a change in pull request #11674: [FLINK-16887][table-planner-blink] Refactor retraction rules to support inferring ChangelogMode URL: https://github.com/apache/flink/pull/11674#discussion_r407303722
########## File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/trait/UpdateKindTrait.scala ########## @@ -0,0 +1,79 @@ +/* + * 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.plan.`trait` + +import org.apache.calcite.plan.{RelOptPlanner, RelTrait, RelTraitDef} + +/** + * UpdateKindTrait is used to describe the kind of update operation. + */ +class UpdateKindTrait(val updateKind: UpdateKind) extends RelTrait { + + override def satisfies(relTrait: RelTrait): Boolean = relTrait match { + case other: UpdateKindTrait => + // should totally match + other.updateKind == this.updateKind + case _ => false + } + + override def getTraitDef: RelTraitDef[_ <: RelTrait] = UpdateKindTraitDef.INSTANCE + + override def register(planner: RelOptPlanner): Unit = {} + + override def hashCode(): Int = updateKind.hashCode() + + override def equals(obj: Any): Boolean = obj match { + case t: UpdateKindTrait => this.updateKind.equals(t.updateKind) + case _ => false + } + + override def toString: String = s"[${updateKind.toString}]" +} + +object UpdateKindTrait { + val NO_UPDATE = new UpdateKindTrait(UpdateKind.NO_UPDATE) Review comment: `NO_UPDATE` is not just a placeholder here. For `AppendTableSink` and window aggregation, it requires children should produce `NO_UPDATE` trait. It doesnt make sense to require a `ONLY_UPDATE_AFTER` or `BEFORE_AND_AFTER` in this case. Merging `ONLY_UPDATE_AFTER` and `BEFORE_AND_AFTER` into `ModifyKind.UPDATE` maybe confusing. Becasue a default `BEFORE_AND_AFTER` maybe wrong in some cases (e.g. upsert source produce `ONLY_AFTER`). Separating into 2 traits in on purpose, and I think it makes things cleaner. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services