[
https://issues.apache.org/jira/browse/CALCITE-7052?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17965507#comment-17965507
]
Mihai Budiu commented on CALCITE-7052:
--------------------------------------
In fact, I suspect that the implementation of aliases in GROUP BY/HAVING has
been broken from the start.
I think that there are two principles that have to guide the semantics of
queries that use aliases:
- all queries that are legal using a standard interpretation are legal when
aliases in GROUP BY, HAVING, and SELECT are allowed, and they all have the same
exact meaning
- all queries that are ambiguous in a standard interpretation remain ambiguous
(and thus illegal) when aliases are allowed
I think these principles are very important, because enabling aliases should
NOT change the meaning of any queries. It should only enable new queries to be
executed.
These principles suggest that several tests for aliases are actually incorrect.
I will hopefully submit a PR which fixes these problems.
> When conformance specifies isGroupbyAlias = true the validator rejects legal
> queries
> ------------------------------------------------------------------------------------
>
> Key: CALCITE-7052
> URL: https://issues.apache.org/jira/browse/CALCITE-7052
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.40.0
> Reporter: Mihai Budiu
> Priority: Minor
>
> The following test in SqlValidatorTest passes:
> {code:java}
> sql("SELECT ALL - cor0.empno AS empno "
> + "FROM emp AS cor0 GROUP BY empno HAVING NOT ( cor0.empno ) IS NULL")
> .ok();
> {code}
> but the following test fails:
> {code:java]
> sql("SELECT ALL - cor0.empno AS empno "
> + "FROM emp AS cor0 GROUP BY empno HAVING NOT ( cor0.empno ) IS NULL")
> .withConformance(SqlConformanceEnum.LENIENT)
> .ok();
> {code}
> with the error:
> {code}
> Expression 'COR0.EMPNO' is not being grouped
> {code}
> The validator incorrectly rewrites the query as:
> SELECT ALL - `COR0`.`EMPNO` AS `EMPNO`
> FROM `EMP` AS `COR0`
> GROUP BY - `COR0`.`EMPNO`
> HAVING NOT `COR0`.`EMPNO` IS NULL
> because in this conformance isGroupbyAlias returns true.
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)