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

Haris Sattar commented on CALCITE-7508:
---------------------------------------

Hi [~krooswu] ,


Apologies for the missing context — this issue only manifests when using a 
dialect where hasImplicitTableAlias() returns true (e.g., PrestoSqlDialect). 
With the default dialect, alias uniquification works correctly and the mismatch 
doesn't occur.

 

To reproduce, use a correlated scalar subquery in the SELECT list with 
PrestoSqlDialect:

  

RelToSqlConverter converter = new RelToSqlConverter(PrestoSqlDialect.DEFAULT);

  

With a query like:

 

SELECT id, (SELECT SUM(value) FROM table_b WHERE table_b.id = table_a.id) AS 
total FROM table_a

  

The correlation reference will emit an alias (e.g., "t0"."id") that doesn't 
match the outer table's FROM clause (AS "t").

> RelToSqlConverter registers wrong alias for correlation variable in 
> visit(Project)
> ----------------------------------------------------------------------------------
>
>                 Key: CALCITE-7508
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7508
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.39.0
>            Reporter: Haris Sattar
>            Assignee: krooswu
>            Priority: Major
>              Labels: pull-request-available
>
> *Example:*
> Input RelNode tree: a correlated scalar subquery where the outer table is 
> table_a and the inner table is table_b, correlated on column "id".
> *Expected SQL output:*
> SELECT "id",
>   (SELECT SUM("value") FROM "table_b" AS "t1"
>    WHERE "id" = "t"."id") AS "total_value"
> FROM "table_a" AS "t"
> *Actual SQL output:*
> SELECT "id",
>   (SELECT SUM("value") FROM "table_b" AS "t1"
>    WHERE "id" = "t0"."id") AS "total_value"
> FROM "table_a" AS "t"
> The correlation reference emits "t0"."id" but the outer table's FROM clause 
> says AS "t". "t0" does not exist in the query. The SQL is invalid and will be 
> rejected by the execution engine.



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

Reply via email to