[
https://issues.apache.org/jira/browse/CALCITE-7343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18048960#comment-18048960
]
krooswu commented on CALCITE-7343:
----------------------------------
*Progress Update:*
Working on CALCITE-7343.
*Root Cause:* Correlated subqueries require outer table aliases, but
{{RelToSqlConverter}} doesn't detect this requirement.
*Solution:* Implementing a context flag pattern to propagate alias requirements
from parent nodes (Project/Filter) to TableScan.
*Status:*
* ✅ Root cause identified
* 🔄 Implementation in progress
* Starting with Project (SELECT list) - the primary reported scenario
* Will extend to other operators incrementally
This is a broader fix than initially scoped. Taking an incremental approach.
> RelToSqlConverter generate wrong sql when scalar correlated sub-query in
> Project
> --------------------------------------------------------------------------------
>
> Key: CALCITE-7343
> URL: https://issues.apache.org/jira/browse/CALCITE-7343
> Project: Calcite
> Issue Type: Bug
> Reporter: xiong duan
> Assignee: krooswu
> Priority: Major
>
> The unit test in RelToSqlConverterTest:
> {code:java}
> @Test void testProjectScalarSubquery() {
> final String sql = "SELECT \"EMPNO\", (SELECT COUNT(*) AS \"c\"\n" +
> "FROM \"EMP\"\n" +
> "WHERE \"MGR\" < \"t\".\"MGR\") AS \"$f1\"\n" +
> "FROM \"EMP\" as \"t\"\n" +
> "WHERE \"SAL\" > 10";
> final String expected = "SELECT \"EMPNO\", (SELECT COUNT(*) AS \"c\"\n" +
> "FROM \"SCOTT\".\"EMP\"\n" +
> "WHERE \"MGR\" < \"t\".\"MGR\") AS \"$f1\"\n" +
> "FROM \"SCOTT\".\"EMP\"\n" +
> "WHERE CAST(\"SAL\" AS DECIMAL(12, 2)) > 10.00";
> sql(sql)
> .schema(CalciteAssert.SchemaSpec.JDBC_SCOTT)
> .withCalcite()
> .ok(expected);
> } {code}
> The expected Sql should be:
> {code:java}
> final String expected = "SELECT \"EMPNO\", (SELECT COUNT(*) AS \"c\"\n" +
> "FROM \"SCOTT\".\"EMP\"\n" +
> "WHERE \"MGR\" < \"t\".\"MGR\") AS \"$f1\"\n" +
> "FROM \"SCOTT\".\"EMP\" as \"t\"\n" +
> "WHERE CAST(\"SAL\" AS DECIMAL(12, 2)) > 10.00"; {code}
> "SCOTT"."EMP" should have the alias t.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)