xiong duan created CALCITE-7355:
-----------------------------------

             Summary: RelToSqlConverter throws an exception when the join 
condition contains a correlated subquery
                 Key: CALCITE-7355
                 URL: https://issues.apache.org/jira/browse/CALCITE-7355
             Project: Calcite
          Issue Type: Bug
            Reporter: xiong duan


The unit test in RelToSqlConverterTest:
{code:java}
@Test void testCorrelateInJoinCondition() {
  final String sql = "SELECT E.EMPNO\n"
      + "FROM EMP E\n"
      + "JOIN DEPT D ON E.DEPTNO = D.DEPTNO\n"
      + "AND D.DEPTNO = (\n"
      + "  SELECT MIN(D_INNER.DEPTNO)\n"
      + "  FROM DEPT D_INNER\n"
      + "  WHERE D_INNER.DEPTNO = E.DEPTNO)";
  final String expected = "";
  sql(sql)
      .schema(CalciteAssert.SchemaSpec.JDBC_SCOTT)
      .withCalcite()
      .ok(expected);
} {code}
The exception:
{code:java}
 java.lang.NullPointerException: variable $cor0 is not found
        at java.base/java.util.Objects.requireNonNull(Objects.java:347)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor.getAliasContext(SqlImplementor.java:1589)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$BaseContext.getAliasContext(SqlImplementor.java:1623)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:700)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:1217)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.callToSql(SqlImplementor.java:901)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:874)
        at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:501)
 {code}



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

Reply via email to