[ https://issues.apache.org/jira/browse/HIVE-24633?focusedWorklogId=537313&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-537313 ]
ASF GitHub Bot logged work on HIVE-24633: ----------------------------------------- Author: ASF GitHub Bot Created on: 18/Jan/21 09:54 Start Date: 18/Jan/21 09:54 Worklog Time Spent: 10m Work Description: kasakrisz commented on a change in pull request #1865: URL: https://github.com/apache/hive/pull/1865#discussion_r559440784 ########## File path: ql/src/test/queries/clientpositive/cte_8.q ########## @@ -0,0 +1,34 @@ +set hive.cli.print.header=true; + +create table t1(int_col int, bigint_col bigint); + +insert into t1 values(1, 2), (3, 4); + +explain cbo +with cte1(a, b) as (select int_col x, bigint_col y from t1) +select a, b from cte1; + +with cte1(a, b) as (select int_col x, bigint_col y from t1) +select a, b from cte1; + +with cte1(a) as (select int_col x, bigint_col y from t1) Review comment: Our behavior is the same as Postgres: ambiguous column reference is only allowed when the main query has `select *` If the main query has an explicit reference to the ambiguous column in any clause the query won't compile. Added test case for both scenario. The difference between Hive and Postgres is the final column names int the result set: ``` with cte1(a) as (select int_col x, bigint_col a from t1) select * from cte1; ``` Postgres: `a, a` Hive: `cte1.a cte1._col1` After some research I found that we alter the column name to its internal name because CBO cannot handle ambiguous column names: [HIVE-19770](https://issues.apache.org/jira/browse/HIVE-19770) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 537313) Time Spent: 40m (was: 0.5h) > Support CTE with column labels > ------------------------------ > > Key: HIVE-24633 > URL: https://issues.apache.org/jira/browse/HIVE-24633 > Project: Hive > Issue Type: Improvement > Components: Parser > Reporter: Krisztian Kasa > Assignee: Krisztian Kasa > Priority: Major > Labels: pull-request-available > Time Spent: 40m > Remaining Estimate: 0h > > {code} > with cte1(a, b) as (select int_col x, bigint_col y from t1) > select a, b from cte1{code} > {code} > a b > 1 2 > 3 4 > {code} > {code} > <query expression> ::= > [ <with clause> ] <query expression body> > [ <order by clause> ] [ <result offset clause> ] [ <fetch first clause> ] > <with clause> ::= > WITH [ RECURSIVE ] <with list> > <with list> ::= > <with list element> [ { <comma> <with list element> }... ] > <with list element> ::= > <query name> [ <left paren> <with column list> <right paren> ] > AS <table subquery> [ <search or cycle clause> ] > <with column list> ::= > <column name list> > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)