Silun Dong created CALCITE-7212:
-----------------------------------

             Summary: VariablesSet of Project is lost during 
RelStructuredTypeFlattener processing
                 Key: CALCITE-7212
                 URL: https://issues.apache.org/jira/browse/CALCITE-7212
             Project: Calcite
          Issue Type: Bug
          Components: core
            Reporter: Silun Dong


When RelStructuredTypeFlattener rewrites Project, it forgets the variablesSet 
attribute. 
{code:java}
public void rewriteRel(LogicalProject rel) {
  //......
  final RelNode newRel = relBuilder.push(newInput)
      .projectNamed(flattenedExpList.leftList(), flattenedExpList.rightList(),
          true)                         // lost variablesSet
      .hints(rel.getHints())
      .build();
  setNewForOldRel(rel, newRel);
} {code}
Many test classes will reach here when generating the initial plan (via the 
convertSqlToRel2 call of SqlTest). For example, the testTwoLevelDecorrelate in 
RelOptRulesTest:
{code:java}
SELECT d1.name, d1.deptno + (
SELECT e1.empno
FROM emp e1
WHERE d1.deptno = e1.deptno and
    e1.sal = (SELECT max(sal)
              FROM emp e2
              WHERE e1.sal = e2.sal and
                  e1.deptno = e2.deptno and
                  d1.deptno < e2.deptno))
FROM dept d1 


// initial plan
LogicalProject(NAME=[$1], EXPR$1=[+($0, $SCALAR_QUERY({      // lost 
variablesSet $cor0
LogicalProject(EMPNO=[$0])
  LogicalFilter(condition=[AND(=($cor0.DEPTNO, $7), =($5, $SCALAR_QUERY({
LogicalAggregate(group=[{}], EXPR$0=[MAX($0)])
  LogicalProject(SAL=[$5])
    LogicalFilter(condition=[AND(=($cor1.SAL, $5), =($cor1.DEPTNO, $7), 
<($cor0.DEPTNO, $7))])
      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
})))], variablesSet=[[$cor1]])
    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
}))])
  LogicalTableScan(table=[[CATALOG, SALES, DEPT]]){code}
Although it does not cause an error now, I think it is a minor bug that can be 
fixed by adding the variablesSet parameter when rewriting in the rewriteRel.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to