xiedeyantu commented on code in PR #4676:
URL: https://github.com/apache/calcite/pull/4676#discussion_r2609132687


##########
plus/src/test/java/org/apache/calcite/adapter/tpch/TpchTest.java:
##########
@@ -833,6 +848,74 @@ private CalciteAssert.AssertThat with() {
         });
   }
 
+  /** Test case for <a 
href="https://issues.apache.org/jira/browse/CALCITE-7319";>[CALCITE-7319]
+   * FILTER_INTO_JOIN rule loses correlation variable context in 
HepPlanner</a>. */
+  @Test public void optimizeQuery2()

Review Comment:
   I added the following case to RelOptRulesTest. Would this make it simpler 
and easier to observe changes?
   ```
     @Test void testFilterIntoJoinMissingVariableCor() {
       final String sql = "SELECT E.EMPNO\n"
           + "FROM EMP E\n"
           + "JOIN DEPT D ON E.DEPTNO = D.DEPTNO\n"
           + "WHERE  E.EMPNO > 10 AND D.DEPTNO = (\n"
           + "  SELECT MIN(D_INNER.DEPTNO)\n"
           + "  FROM DEPT D_INNER\n"
           + "  WHERE D_INNER.DEPTNO = E.DEPTNO)";
       sql(sql)
           .withExpand(false)
           .withDecorrelate(false)
           .withRule(CoreRules.FILTER_INTO_JOIN)
           .check();
     }
   ```
   RelOptRulesTest.xml
   ```
     <TestCase name="testFilterIntoJoinMissingVariableCor">
       <Resource name="sql">
         <![CDATA[SELECT E.EMPNO
   FROM EMP E
   JOIN DEPT D ON E.DEPTNO = D.DEPTNO
   WHERE  E.EMPNO > 10 AND D.DEPTNO = (
     SELECT MIN(D_INNER.DEPTNO)
     FROM DEPT D_INNER
     WHERE D_INNER.DEPTNO = E.DEPTNO)]]>
       </Resource>
       <Resource name="planBefore">
         <![CDATA[
   LogicalProject(EMPNO=[$0])
     LogicalFilter(condition=[AND(>($0, 10), =($9, $SCALAR_QUERY({
   LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
     LogicalProject(DEPTNO=[$0])
       LogicalFilter(condition=[=($0, $cor0.DEPTNO)])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
   })))], variablesSet=[[$cor0]])
       LogicalJoin(condition=[=($7, $9)], joinType=[inner])
         LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
   ]]>
       </Resource>
       <Resource name="planAfter">
         <![CDATA[
   LogicalProject(EMPNO=[$0])
     LogicalFilter(condition=[=($9, $SCALAR_QUERY({
   LogicalAggregate(group=[{}], EXPR$0=[MIN($0)])
     LogicalProject(DEPTNO=[$0])
       LogicalFilter(condition=[=($0, $cor0.DEPTNO)])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
   }))])
       LogicalJoin(condition=[=($7, $9)], joinType=[inner])
         LogicalFilter(condition=[>($0, 10)])
           LogicalTableScan(table=[[CATALOG, SALES, EMP]])
         LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
   ]]>
       </Resource>
     </TestCase>
   ```



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