Files
impala/testdata/workloads/functional-query/queries/QueryTest/with-clause.test
Matthew Jacobs 164687ad81 IMPALA-1357: Analysis of WithClause pollutes global state
The analysis of a with clause should have its own global state so the
local view(s) can be analyzed without polluting the global state of the
parent QueryStmt. This might not always matter, but in a complex query
involving a with clause that contained a subquery, re-analysis of the
WithClause after the subquery rewrite resulted in an invalid Exists
conjunct being registered in the parent analyzer's global state. The
Exists conjunct was assigned to a scan node which then failed a
pre-condition check.

Change-Id: Ib020787b2e1ff202d96fe1b92bd9740897ab32a0
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/4825
Reviewed-by: Matthew Jacobs <mj@cloudera.com>
Tested-by: jenkins
(cherry picked from commit 629a8652c5a290054a8e582cc5cb5768a3ee67a8)
Reviewed-on: http://gerrit.sjc.cloudera.com:8080/5038
2014-10-30 16:50:00 -07:00

124 lines
2.9 KiB
Plaintext

====
---- QUERY
# Basic test with a single with-clause view.
with t as (select int_col x, bigint_col y from functional.alltypestiny)
select count(x), count(y) from t
---- RESULTS
8,8
---- TYPES
BIGINT, BIGINT
====
---- QUERY
# Basic test with a single with-clause view that references a virtual view.
with t as (select abc x, xyz y from functional.complex_view)
select x, y from t order by y limit 10
---- RESULTS
2,'0'
2,'1'
---- TYPES
BIGINT, STRING
====
---- 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))
select x, y from t2
---- RESULTS
1,10
---- TYPES
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))
select * from t1 union all select * from t2 union all (select * from t3) order by x limit 20
---- RESULTS
0,0
0,0
0,0
0,0
1,10
1,10
1,10
1,10
1,10
2,20
3,30
---- TYPES
INT, BIGINT
====
---- 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),
t3 as (select int_col x, bigint_col y from functional.alltypessmall limit 2)
select * from t1, t2, t3 where t1.x = t2.x and t2.x = t3.x
---- RESULTS
0,0,0,0,0,0
1,10,1,10,1,10
---- TYPES
INT, BIGINT, INT, BIGINT, INT, BIGINT
====
---- QUERY
# Self-join of with-clause table to make sure the join op is properly set
# in the cloned inline-view instances.
with t as (select int_col x, bigint_col y from functional.alltypestiny order by id limit 2)
select * from t t1 left outer join t t2 on t1.y = t2.x full outer join t t3 on t2.y = t3.x
order by t1.x limit 10
---- RESULTS
0,0,0,0,0,0
1,10,NULL,NULL,NULL,NULL
NULL,NULL,NULL,NULL,1,10
---- TYPES
INT, BIGINT, INT, BIGINT, INT, BIGINT
====
---- QUERY
# Multiple with clauses. One for the UnionStmt and one for each union operand.
with t1 as (values('a', 'b'))
(with t2 as (values('c', 'd')) select * from t2) union all
(with t3 as (values('e', 'f')) select * from t3)
---- RESULTS
'e','f'
'c','d'
---- TYPES
STRING, STRING
====
---- QUERY
# With clause containing an order by element that should be cloned properly.
with t1 as (select tinyint_col, count(*) from alltypesagg group by 1
order by 1 desc nulls last limit 10) select * from t1;
---- RESULTS
9,1000
8,1000
7,1000
6,1000
5,1000
4,1000
3,1000
2,1000
1,1000
NULL,2000
---- TYPES
TINYINT, BIGINT
====
---- QUERY
# IMPALA-1357: Analysis of WithClause pollutes global state
select 1 from (
with w as (
select 1 from alltypestiny
where exists (select 1 from alltypestiny))
select 1 from w) tt
---- RESULTS
1
1
1
1
1
1
1
1
---- TYPES
TINYINT
====