You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2026/02/17 15:46:00 UTC

[jira] [Updated] (HIVE-29466) Ambiguous table alias exception when using CTE suggester

     [ https://issues.apache.org/jira/browse/HIVE-29466?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ASF GitHub Bot updated HIVE-29466:
----------------------------------
    Labels: pull-request-available  (was: )

> Ambiguous table alias exception when using CTE suggester
> --------------------------------------------------------
>
>                 Key: HIVE-29466
>                 URL: https://issues.apache.org/jira/browse/HIVE-29466
>             Project: Hive
>          Issue Type: Task
>          Components: CBO
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>
> Queries with common table expressions may throw an ambiguity exception when a
> CTE suggester is in-use. 
>  
> {code:sql}
> create table t1 (key int, value int);
> set hive.optimize.cte.materialize.threshold=1;
> set hive.optimize.cte.suggester.class=org.apache.hadoop.hive.ql.optimizer.calcite.CommonTableExpressionIdentitySuggester;
> set hive.optimize.cte.materialize.full.aggregate.only=false;
> explain cbo
> select *
> from (select key from t1 where value = 10) a
> join (select key from t1 where value = 10) b;
> {code}
> Observe that the same expression "select key from t1 where value = 10" appears twice in the query and thus when {{hive.optimize.cte.suggester.class}} is used the optimizer will detect the equivalence and rewrite the query to use the CTE. However, the optimizer will assign the same alias (ie., "cte_suggestion_0") to both expressions causing the following exception:
> {noformat}
>  org.apache.hadoop.hive.ql.parse.SemanticException: Line 0:-1 Ambiguous table alias 'cte_suggestion_0'
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.processTable(SemanticAnalyzer.java:1159)
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.processJoin(SemanticAnalyzer.java:1671)
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.doPhase1(SemanticAnalyzer.java:1896)
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.doPhase1(SemanticAnalyzer.java:2111)
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.doPhase1(SemanticAnalyzer.java:1746)
> 	at org.apache.hadoop.hive.ql.parse.CalcitePlanner.genOPTree(CalcitePlanner.java:632)
> 	at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:13222)
> 	at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:480)
> 	at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:358)
> 	at org.apache.hadoop.hive.ql.parse.ExplainSemanticAnalyzer.analyzeInternal(ExplainSemanticAnalyzer.java:187)
> 	at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:358)
> 	at org.apache.hadoop.hive.ql.Compiler.analyze(Compiler.java:224)
> 	at org.apache.hadoop.hive.ql.Compiler.compile(Compiler.java:109)
> 	at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:498)
> 	at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:450)
> 	at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:414)
> 	at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:408)
> 	at org.apache.hadoop.hive.ql.reexec.ReExecDriver.compileAndRespond(ReExecDriver.java:126)
> 	at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:234)
> 	at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:259)
> 	at org.apache.hadoop.hive.cli.CliDriver.processCmd1(CliDriver.java:203)
> 	at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:129)
> 	at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:430)
> 	at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:358)
> 	at org.apache.hadoop.hive.ql.QTestUtil.executeClientInternal(QTestUtil.java:760)
> 	at org.apache.hadoop.hive.ql.QTestUtil.executeClient(QTestUtil.java:730)
> 	at org.apache.hadoop.hive.cli.control.CoreCliDriver.runTest(CoreCliDriver.java:115)
> 	at org.apache.hadoop.hive.cli.control.CliAdapter.runTest(CliAdapter.java:139)
> {noformat}



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