[ 
https://issues.apache.org/jira/browse/CALCITE-6007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17766033#comment-17766033
 ] 

Julian Hyde commented on CALCITE-6007:
--------------------------------------

The problem is that the generated SQL is invalid. That should be the summary.

You assert that the solution would be for the parser to assign an alias when 
creating the SqlWith node. I'm not sure that's desirable. We try to keep the 
AST as close as possible to the original SQL. Maybe add an alias while 
generating the SQL.

Would a similar problem happen with other queries that have a subquery with no 
alias? E.g.
{code:java}
select a, b
from (
  select 1 as a, 2 as b)
where a is not null{code}

> Sqlwith as subquery without alias doesn't have correct alias setup
> ------------------------------------------------------------------
>
>                 Key: CALCITE-6007
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6007
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.34.0, 1.35.0
>            Reporter: Wenrui Meng
>            Priority: Major
>
> {code:java}
> SELECT
>   a,
>   b
> FROM (
>   WITH
>     sub AS (
>     SELECT
>       1 AS a,
>       2 AS b)
>   SELECT
>     *
>   FROM
>     sub)
> WHERE
>   a IS NOT null
> {code}
> It will generate the following SQL statement after validation
> {code:java}
> SELECT
>   EXPR$0.a,
>   EXPR$0.b
> FROM (
>   WITH
>     sub AS (
>     SELECT
>       1 AS a,
>       2 AS b)
>   SELECT
>     sub.a AS a, sub.b AS b
>   FROM
>     sub)
> WHERE
>   EXPR$0.a IS NOT null
> {code}
> The validated SQL become invalid since there is no EXPR$0 alias append for 
> the SqlWith sub query but used in the expression outside. 



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

Reply via email to