[
https://issues.apache.org/jira/browse/CALCITE-2904?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16791503#comment-16791503
]
Julian Hyde commented on CALCITE-2904:
--------------------------------------
I haven't read what the SQL standard says about references to tables whose
aliases are the same, but it's possible that it doesn't allow them. It might be
worth reading the standard. If this is not legal SQL, we don't need to fix it.
As you've discovered, we rely heavily on converting unqualified references to
qualified references.
One idea is to generate an alias - for internal use only - that is guaranteed
to be unique. It only needs to happen when one table alias obscures another
alias with the same name. The internal alias would allow columns of the
obscured table to be referenced.
> Column not found in table when query contain duplicate table alias
> -------------------------------------------------------------------
>
> Key: CALCITE-2904
> URL: https://issues.apache.org/jira/browse/CALCITE-2904
> Project: Calcite
> Issue Type: Bug
> Components: core
> Reporter: Haisheng Yuan
> Assignee: Danny Chan
> Priority: Major
>
> Repro:
> In SqlToRelConverterTest.java, add this test.
> {code:java}
> @Test public void testDuplicateTableAlias() {
> final String sql = "select * from (values 4) as t(c) "
> + "left join lateral "
> + "(select c,c*a from "
> + " (values 2) as t(a)"
> + ") as r(d,c) "
> + "using(c)";
> sql(sql).ok();
> }
> {code}
> Error message:
> {code:java}
> org.apache.calcite.runtime.CalciteContextException: At line 1, column 60:
> Column 'C' not found in table 'T'
> {code}
> The tables with same aliases are at different level. Postgres can parse this
> query without any issue. Not sure if this is expected behavior or not in
> calcite.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)