mirror of
https://github.com/apache/impala.git
synced 2026-01-08 12:02:54 -05:00
IMPALA-898: Support explicit column names in WITH-clause views.
Example: WITH t(c1, c2) AS (SELECT int_col, bool_col FROM functional.alltypes) SELECT * FROM t This will create a local view with the 'int_col' and 'bool_col' columns labeled as 'c1' and 'c2'. If the number of labels is less than the number of columns, then the remaining columns in the local view will be labeled as the corresponding columns in the query statement. Therefore, this is also a valid query (only 'int_col' will be labeled as 'c1'): WITH t(c1) AS (SELECT int_col, bool_col FROM functional.alltypes) SELECT * FROM t Change-Id: Ie3a559ca9eaf95c6980c5695a49f02010c42899b Reviewed-on: http://gerrit.cloudera.org:8080/717 Reviewed-by: Vlad Berindei <vlad.berindei@cloudera.com> Tested-by: Internal Jenkins
This commit is contained in:
committed by
Internal Jenkins
parent
bcc73a36da
commit
cfc3952a83
@@ -19,9 +19,36 @@ select x, y from t order by y limit 10
|
||||
BIGINT, STRING
|
||||
====
|
||||
---- QUERY
|
||||
# Basic tests with a single with-clause view with column labels.
|
||||
with t(c1, c2) as (select int_col, bigint_col y from functional.alltypestiny)
|
||||
select * from t limit 1
|
||||
---- RESULTS
|
||||
0,0
|
||||
---- TYPES
|
||||
INT, BIGINT
|
||||
---- LABELS
|
||||
C1, C2
|
||||
====
|
||||
---- QUERY
|
||||
with t(c1) as (select int_col, bigint_col from functional.alltypestiny)
|
||||
select * from t limit 1
|
||||
---- RESULTS
|
||||
0,0
|
||||
---- TYPES
|
||||
INT, BIGINT
|
||||
---- LABELS
|
||||
C1, BIGINT_COL
|
||||
====
|
||||
---- QUERY
|
||||
with t(c1, c2) as (select int_col from functional.alltypestiny)
|
||||
select * from t limit 1
|
||||
---- CATCH
|
||||
AnalysisException: WITH-clause view 't' returns 1 columns, but 2 labels were specified.
|
||||
====
|
||||
---- QUERY
|
||||
# Multiple views in with-clause. Only one view is used.
|
||||
with t1 as (select int_col x, bigint_col y from functional.alltypestiny),
|
||||
t2 as (select 1 x , 10 y), t3 as (values(2 x , 20 y), (3, 30))
|
||||
t2 as (select 1 x, 10 y), t3 as (values(2 x, 20 y), (3, 30))
|
||||
select x, y from t2
|
||||
---- RESULTS
|
||||
1,10
|
||||
@@ -31,7 +58,7 @@ TINYINT, TINYINT
|
||||
---- QUERY
|
||||
# Multiple views in with-clause. All views are used in a union.
|
||||
with t1 as (select int_col x, bigint_col y from functional.alltypestiny),
|
||||
t2 as (select 1 x , 10 y), t3 as (values(2 x , 20 y), (3, 30))
|
||||
t2 as (select 1 x, 10 y), t3 as (values(2 x, 20 y), (3, 30))
|
||||
select * from t1 union all select * from t2 union all (select * from t3) order by x limit 20
|
||||
---- RESULTS
|
||||
0,0
|
||||
@@ -49,6 +76,18 @@ select * from t1 union all select * from t2 union all (select * from t3) order b
|
||||
INT, BIGINT
|
||||
====
|
||||
---- QUERY
|
||||
with t1(c1, c2) as (select int_col x, bigint_col y from functional.alltypestiny),
|
||||
t2(c3, c4) as (select 1 x, 10 y)
|
||||
select * from t1 limit 1 union all select * from t2 limit 1
|
||||
---- RESULTS
|
||||
0,0
|
||||
1,10
|
||||
---- TYPES
|
||||
INT, BIGINT
|
||||
---- LABELS
|
||||
C1, C2
|
||||
====
|
||||
---- QUERY
|
||||
# Multiple views in with-clause. All views are used in a join.
|
||||
with t1 as (select int_col x, bigint_col y from functional.alltypes limit 2),
|
||||
t2 as (select int_col x, bigint_col y from functional.alltypestiny limit 2),
|
||||
|
||||
Reference in New Issue
Block a user