libenchao commented on code in PR #24567: URL: https://github.com/apache/flink/pull/24567#discussion_r1542265389
########## flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUpsertKeys.scala: ########## @@ -186,6 +187,27 @@ class FlinkRelMdUpsertKeys private extends MetadataHandler[UpsertKeys] { } def getUpsertKeys(rel: Window, mq: RelMetadataQuery): JSet[ImmutableBitSet] = { + // If it's a ROW_NUMBER rank, then the upsert keys are partition by key and order key. Review Comment: the upsert keys should be : partition key + order key + rownumber column? ########## flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUpsertKeys.scala: ########## @@ -186,6 +187,27 @@ class FlinkRelMdUpsertKeys private extends MetadataHandler[UpsertKeys] { } def getUpsertKeys(rel: Window, mq: RelMetadataQuery): JSet[ImmutableBitSet] = { Review Comment: And since you changed `FlinkRelMdUniqueKeys`, it would be good to also add tests for it in `FlinkRelMdUniqueKeysTest` ########## flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/runtime/stream/sql/RankITCase.scala: ########## @@ -656,18 +656,14 @@ class RankITCase(mode: StateBackendMode) extends StreamingWithStateTestBase(mode "(true,1,book,b,3,2)", "(true,2,fruit,a,2,1)", "(true,3,book,a,1,2)", - "(true,3,book,a,1,2)", Review Comment: Is this change expected? ########## flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUpsertKeys.scala: ########## @@ -186,6 +187,27 @@ class FlinkRelMdUpsertKeys private extends MetadataHandler[UpsertKeys] { } def getUpsertKeys(rel: Window, mq: RelMetadataQuery): JSet[ImmutableBitSet] = { + // If it's a ROW_NUMBER rank, then the upsert keys are partition by key and order key. + if (rel.groups.length == 1) { Review Comment: `Window` can have multiple groups, if any one of them contains `row_number`, it could be an upsert key condidate ########## flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUpsertKeys.scala: ########## @@ -186,6 +187,27 @@ class FlinkRelMdUpsertKeys private extends MetadataHandler[UpsertKeys] { } def getUpsertKeys(rel: Window, mq: RelMetadataQuery): JSet[ImmutableBitSet] = { Review Comment: It seems like a good improvement to both unique key and upsert key metadata, do you think it's possible to put it in `FlinkRelMdUniqueKeys` and reuse it in `FlinkRelMdUpsertKeys`, just like `FlinkRelMdUniqueKeys.getRankUniqueKeys`? ########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/FlinkProjectWindowTransposeRule.java: ########## @@ -0,0 +1,294 @@ +/* + * 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.rules.logical; + +import org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery; + +import org.apache.flink.shaded.guava31.com.google.common.collect.ImmutableList; + +import org.apache.calcite.plan.RelOptCluster; +import org.apache.calcite.plan.RelOptRuleCall; +import org.apache.calcite.plan.RelRule; +import org.apache.calcite.rel.RelCollations; +import org.apache.calcite.rel.RelFieldCollation; +import org.apache.calcite.rel.core.Project; +import org.apache.calcite.rel.core.Window; +import org.apache.calcite.rel.logical.LogicalProject; +import org.apache.calcite.rel.logical.LogicalWindow; +import org.apache.calcite.rel.rules.ProjectRemoveRule; +import org.apache.calcite.rel.rules.TransformationRule; +import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.rex.RexCall; +import org.apache.calcite.rex.RexInputRef; +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.rex.RexShuttle; +import org.apache.calcite.sql.SqlAggFunction; +import org.apache.calcite.util.BitSets; +import org.apache.calcite.util.ImmutableBitSet; +import org.immutables.value.Value; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * Copied from {@link org.apache.calcite.rel.rules.ProjectWindowTransposeRule} The only difference + * is line 251 to 257, the upsert keys of window are kept not pushed down. Planner rule that pushes Review Comment: Could you add the reasoning why you want to do this change? -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org