You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2025/07/29 22:26:00 UTC
[jira] [Resolved] (CALCITE-7112) Correlation variable in HAVING clause causes UnsupportedOperationException in RelToSql conversion
[ https://issues.apache.org/jira/browse/CALCITE-7112?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mihai Budiu resolved CALCITE-7112.
----------------------------------
Resolution: Fixed
Fixed in https://github.com/apache/calcite/commit/859469d9eab0d271932a603ea4f6d6872c1b9cd1
Thank you for the fix [~zrlpar]
Thank you for the review [~nobigo]
> Correlation variable in HAVING clause causes UnsupportedOperationException in RelToSql conversion
> -------------------------------------------------------------------------------------------------
>
> 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
> Priority: Minor
> Labels: pull-request-available
> 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)