weiqingy commented on code in PR #28218:
URL: https://github.com/apache/flink/pull/28218#discussion_r3368827209
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/physical/FlinkExpandConversionRule.scala:
##########
@@ -68,6 +70,9 @@ class FlinkExpandConversionRule(flinkConvention: Convention)
val toCollation = requiredTraits.getTrait(RelCollationTraitDef.INSTANCE)
transformedNode = satisfyCollation(flinkConvention, transformedNode,
toCollation)
}
+ if (transformedNode == null) {
Review Comment:
This guard handles the `satisfyTraitsBySelf` path, but `satisfyCollation`
has a second caller — `satisfyTraitsByInput` at line 87 — that now also
receives the `null` you introduced. There `finalRel` flows straight into
`checkSatisfyRequiredTrait(finalRel, …)`, which dereferences `node.getTraitSet`
and will NPE. So an input that reaches the trait-pushdown branch with the same
out-of-bounds collation swaps the IndexOutOfBoundsException for a
NullPointerException. Could we either apply the same guard at line 87, or hoist
the bounds check so `satisfyCollation` never hands `null` to an unprepared
caller? A test exercising the input-pushdown path would lock it down.
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/physical/FlinkExpandConversionRule.scala:
##########
@@ -151,6 +156,12 @@ object FlinkExpandConversionRule {
requiredCollation: RelCollation): RelNode = {
val fromCollation =
node.getTraitSet.getTrait(RelCollationTraitDef.INSTANCE)
if (!fromCollation.satisfies(requiredCollation)) {
+ val fieldCount = node.getRowType.getFieldCount
+ val isValidCollation =
+ requiredCollation.getFieldCollations.asScala.forall(_.getFieldIndex <
fieldCount)
+ if (!isValidCollation) {
Review Comment:
On the bail itself: is the out-of-bounds case always genuinely
unsatisfiable, so dropping the path is strictly safe — or could returning
`null` here turn a currently-plannable query into a
`RelOptPlanner.CannotPlanException` if this converter was the only path
offering it?
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/rules/physical/ExpandConversionRuleFixTest.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * 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.physical;
+
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableEnvironment;
+
+import org.junit.jupiter.api.Test;
+
+public class ExpandConversionRuleFixTest {
+
Review Comment:
This runs the job end to end (datagen + `.collect()`), heavier than the bug
needs — the crash is purely in planning. Rule tests in this package extend
`TableTestBase` and assert the optimized plan via `util.verifyRelPlan(sql)`
(e.g. `RemoveRedundantLocalSortAggRuleTest`), which reproduces a planner crash
without spinning up execution and pins the plan so a later regression that
silently changes it is caught too. Would that harness work here?
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/physical/FlinkExpandConversionRule.scala:
##########
@@ -151,6 +156,12 @@ object FlinkExpandConversionRule {
requiredCollation: RelCollation): RelNode = {
val fromCollation =
node.getTraitSet.getTrait(RelCollationTraitDef.INSTANCE)
if (!fromCollation.satisfies(requiredCollation)) {
+ val fieldCount = node.getRowType.getFieldCount
+ val isValidCollation =
+ requiredCollation.getFieldCollations.asScala.forall(_.getFieldIndex <
fieldCount)
+ if (!isValidCollation) {
+ return null
Review Comment:
Stepping back from the mechanics: under a global aggregate the inner `ORDER
BY b` is semantically dead — the collation on `b` only survives because nothing
dropped it before the row type shrank to one field. Returning `null` treats the
symptom at the trait-satisfaction layer. Did you consider eliminating the
spurious collation upstream instead?
--
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]