[ https://issues.apache.org/jira/browse/CALCITE-7508 ]
Yu Xu deleted comment on CALCITE-7508:
--------------------------------
was (Author: JIRAUSER307770):
Hi, [~krooswu] I’ve looked into this issue over the past couple of days; the
root cause has likely been identified and issue nearly been resolved. If you
haven't started yet—and don't mind—I’ll take over this task. root case:
In `RelToSqlConverter.visit(Project)`, when a correlation variable is defined,
the code directly uses `inputResult.neededAlias` as the alias for the
correlation reference. However, `SqlImplementor.result()` performs alias
deduplication within the global `aliasSet`, leading to the following sequence:
the `FROM` clause of `inputResult.node` actually appears as `AS "t"`;
`inputResult.neededAlias` is re-derived as `"t0"`;
`parseCorrelTable` registers the correlation using `"t0"`, generating `WHERE
"id" = "t0"."id"`;
in the final SQL, the `FROM` clause uses `"t"`, but the correlation reference
points to the non-existent `"t0"`.
> 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
>
> *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)