snuyanzin commented on code in PR #27959:
URL: https://github.com/apache/flink/pull/27959#discussion_r3309343613


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/optimize/CorrelVariableNormalizerShuttleTest.java:
##########
@@ -0,0 +1,185 @@
+/*
+ * 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.optimize;
+
+import org.apache.flink.table.planner.calcite.FlinkRelBuilder;
+import org.apache.flink.table.planner.utils.PlannerMocks;
+
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.CorrelationId;
+import org.apache.calcite.rel.core.JoinRelType;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalJoin;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexSubQuery;
+import org.apache.calcite.sql.SqlOperatorBinding;
+import org.apache.calcite.sql.fun.SqlCollectionTableOperator;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlModality;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link CorrelVariableNormalizerShuttle}. */
+class CorrelVariableNormalizerShuttleTest {
+
+    private FlinkRelBuilder relBuilder;
+    private RexBuilder rexBuilder;
+    private RelOptCluster cluster;
+
+    @BeforeEach
+    void before() {
+        relBuilder = 
PlannerMocks.create().getPlannerContext().createRelBuilder();
+        rexBuilder = relBuilder.getRexBuilder();
+        cluster = relBuilder.getCluster();
+    }
+
+    @Test
+    void testNormalizesIdsInEncounterOrderWithoutNegativeIds() {
+        RelNode input = oneRow();
+        RelDataType correlType = singleFieldType("a");
+        RelNode project =
+                LogicalProject.create(
+                        input,
+                        List.of(),
+                        List.of(
+                                correlField(correlType, new CorrelationId(5)),
+                                correlField(correlType, new CorrelationId(2))),
+                        List.of("a", "b"),
+                        Set.of(new CorrelationId(5), new CorrelationId(2)));
+
+        RelNode normalized = normalize(project);
+        String plan = RelOptUtil.toString(normalized);
+
+        assertThat(plan).contains("$cor1", "$cor2");
+        assertThat(plan).doesNotContain("$cor5", "$cor-", "$cor0");
+    }
+
+    @Test
+    void testNormalizesZeroInputTableFunctionScanRexNodes() {
+        CorrelationId oldId = new CorrelationId(5);
+        RelDataType inputType = singleFieldType("a");
+        RelDataType outputType = singleFieldType("b");
+        SqlCollectionTableOperator tableOperator =
+                new SqlCollectionTableOperator("TABLE", SqlModality.RELATION) {
+                    @Override
+                    public RelDataType inferReturnType(SqlOperatorBinding 
opBinding) {
+                        return outputType;
+                    }
+                };
+
+        RelNode relNode =
+                relBuilder
+                        .push(oneRow())
+                        .functionScan(tableOperator, 0, correlField(inputType, 
oldId))
+                        .correlate(JoinRelType.INNER, oldId)
+                        .build();
+
+        String plan = RelOptUtil.toString(normalize(relNode));
+
+        assertThat(plan).contains("$cor1");
+        assertThat(plan).doesNotContain("$cor5");

Review Comment:
   I fear this kind of tests are fragile
   especially for the case of Calcite upgrade when a bunch of new optimizations 
come around correlated queries.
   Would be better to have SQL related tests only (plan verifications)
   and may be 1-2 Store/Restore tests



-- 
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]

Reply via email to