Niels Pardon created CALCITE-7112:
-------------------------------------

             Summary: correlation variable in HAVING clause throws 
UnsupportedOperationException
                 Key: CALCITE-7112
                 URL: https://issues.apache.org/jira/browse/CALCITE-7112
             Project: Calcite
          Issue Type: Bug
          Components: core
    Affects Versions: 1.40.0
            Reporter: Niels Pardon
            Assignee: Niels Pardon
             Fix For: 1.41.0


We noticed in 
[https://github.com/substrait-io/substrait-java/pull/426#discussion_r2232781963]
 that with Calcite 1.40.0 when a correlation variable appears in a 
LogicalFilter on top of a LogicalAggregate the RelToSqlConverter handles the 
LogicalFilter as a HAVING clause which currently causes an 
UnsupportedOperationException during conversion.

The following simplified example provokes the error:
{code:java}
LogicalProject(variablesSet=[[$cor0]], DEPTNO=[$0], DNAME=[$1], 
$f2=[$SCALAR_QUERY({
LogicalProject(COUNT=[$1])
  LogicalFilter(condition=[=($0, $cor0.DEPTNO)])
    LogicalAggregate(group=[{7}], COUNT=[COUNT()])
      LogicalTableScan(table=[[scott, EMP]])
})])
  LogicalTableScan(table=[[scott, DEPT]])
{code}
The example uses a scalar subquery which has a LogicalFilter with correlation 
variable $cor0 sitting on top of a LogicalAggregate.

This causes:
{code:java}
Caused by: java.lang.UnsupportedOperationException
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.getAliasContext(SqlImplementor.java:1074)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:682)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:1196)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.callToSql(SqlImplementor.java:880)
        at 
org.apache.calcite.rel.rel2sql.SqlImplementor$Context.toSql(SqlImplementor.java:853)
        at 
org.apache.calcite.rel.rel2sql.RelToSqlConverter.visit(RelToSqlConverter.java:477)
        ...
{code}



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

Reply via email to