Files
impala/testdata/workloads/functional-query/queries/QueryTest/nested-map-in-select-list.test
Daniel Becker 8785270451 IMPALA-12147: Allow collections of fixed length types as non-passthrough children of unions
IMPALA-12019 implemented support for collections of fixed length types
in the sorting tuple. This was made possible by implementing the
materialisation of these collections.

Building on this, this change allows such collections as non-passthrough
children of UNION ALL operations. Note that plain UNIONs are not
supported for any collections for other reasons and this patch does not
affect them or any other set operation.

Testing:
Tests in nested-array-in-select-list.test and
nested-map-in-select-list.test check that
 - the newly allowed cases work correctly and
 - the correct error message is given for collections of variable length
   types.

Change-Id: I14c13323d587e5eb8a2617ecaab831c059a0fae3
Reviewed-on: http://gerrit.cloudera.org:8080/19903
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
2023-05-19 22:11:03 +00:00

424 lines
11 KiB
Plaintext

====
---- QUERY
select id, int_map from complextypestbl
---- RESULTS
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
---- TYPES
bigint,string
====
---- QUERY
select id, int_map from complextypestbl where id=1
---- RESULTS
1,'{"k1":1,"k2":100}'
---- TYPES
bigint,string
====
---- QUERY
select id, int_map, int_map_array from complextypestbl
---- RESULTS
1,'{"k1":1,"k2":100}','[{"k1":1}]'
2,'{"k1":2,"k2":null}','[{"k3":null,"k1":1},null,{}]'
3,'{}','[null,null]'
4,'{}','[]'
5,'{}','NULL'
6,'NULL','NULL'
7,'{"k1":null,"k3":null}','NULL'
8,'{"k1":-1}','[{},{"k1":1},{},{}]'
---- TYPES
bigint,string,string
====
---- QUERY
# Same collection used twice in a select list.
select id, int_map, int_map from complextypestbl
---- RESULTS
1,'{"k1":1,"k2":100}','{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}','{"k1":2,"k2":null}'
3,'{}','{}'
4,'{}','{}'
5,'{}','{}'
6,'NULL','NULL'
7,'{"k1":null,"k3":null}','{"k1":null,"k3":null}'
8,'{"k1":-1}','{"k1":-1}'
---- TYPES
bigint,string,string
====
---- QUERY
# Same collection used from two versions of the same table/
select t1.id, t1.int_map, t2.int_map
from complextypestbl t1 join complextypestbl t2
on t1.id = t2.id
---- RESULTS
1,'{"k1":1,"k2":100}','{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}','{"k1":2,"k2":null}'
3,'{}','{}'
4,'{}','{}'
5,'{}','{}'
6,'NULL','NULL'
7,'{"k1":null,"k3":null}','{"k1":null,"k3":null}'
8,'{"k1":-1}','{"k1":-1}'
---- TYPES
bigint,string,string
====
---- QUERY
select id, int_map from complextypestbl union all select id, int_map from complextypestbl
---- RESULTS
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
---- TYPES
bigint,string
====
---- QUERY
# TODO: only UNION ALL is supported. UNION needs several utility functions in the BE, so
# for now we reject it in the FE.
select id, int_map from complextypestbl union select id, int_map from complextypestbl;
---- CATCH
IllegalStateException: UNION, EXCEPT and INTERSECT are not supported for collection types
====
---- QUERY
# Changing a column to a different type leads "non-pass-through" union that does a
# deepcopy on the tuple, which is only implemented for collections of fixed-length types
# in BE for arrays.
select id, map_int_int from map_non_varlen
union all select cast(id as tinyint), map_int_int from map_non_varlen
---- RESULTS
1,'{10:100,11:110,12:120}'
2,'{20:200,21:210,22:220}'
3,'{30:300,31:310,32:320}'
4,'{40:400,41:410,42:420}'
5,'{50:500,51:510,52:520}'
6,'{60:600,61:610,62:620}'
7,'{70:700,71:710,72:720}'
8,'{80:800,81:810,82:820}'
9,'{90:900,91:910,92:920}'
10,'{100:1000,101:1010,102:1020}'
1,'{10:100,11:110,12:120}'
2,'{20:200,21:210,22:220}'
3,'{30:300,31:310,32:320}'
4,'{40:400,41:410,42:420}'
5,'{50:500,51:510,52:520}'
6,'{60:600,61:610,62:620}'
7,'{70:700,71:710,72:720}'
8,'{80:800,81:810,82:820}'
9,'{90:900,91:910,92:920}'
10,'{100:1000,101:1010,102:1020}'
---- TYPES
int,string
====
---- QUERY
# Changing a column to a different type leads "non-pass-through" union that does a
# deepcopy on the tuple, which is only implemented for collections of fixed-length types
# in BE for arrays.
select id, int_map from complextypestbl
union all select cast(id as tinyint), int_map from complextypestbl
---- CATCH
IllegalStateException: only pass-through UNION ALL is supported for collections of variable length types.
====
---- QUERY
# Constants in the select list of unions also lead to "non-pass-through" union.
select 1, map_int_int from map_non_varlen
union all select 2, map_int_int from map_non_varlen;
---- RESULTS
1,'{10:100,11:110,12:120}'
1,'{20:200,21:210,22:220}'
1,'{30:300,31:310,32:320}'
1,'{40:400,41:410,42:420}'
1,'{50:500,51:510,52:520}'
1,'{60:600,61:610,62:620}'
1,'{70:700,71:710,72:720}'
1,'{80:800,81:810,82:820}'
1,'{90:900,91:910,92:920}'
1,'{100:1000,101:1010,102:1020}'
2,'{10:100,11:110,12:120}'
2,'{20:200,21:210,22:220}'
2,'{30:300,31:310,32:320}'
2,'{40:400,41:410,42:420}'
2,'{50:500,51:510,52:520}'
2,'{60:600,61:610,62:620}'
2,'{70:700,71:710,72:720}'
2,'{80:800,81:810,82:820}'
2,'{90:900,91:910,92:920}'
2,'{100:1000,101:1010,102:1020}'
---- TYPES
tinyint,string
====
---- QUERY
# Constants in the select list of unions also lead to "non-pass-through" union.
select 1, int_map from complextypestbl
union all select 2, int_map from complextypestbl;
---- CATCH
IllegalStateException: only pass-through UNION ALL is supported for collections of variable length types.
====
---- QUERY
select 1 from (select int_map from complextypestbl) s
---- RESULTS
1
1
1
1
1
1
1
1
---- TYPES
tinyint
====
---- QUERY
select id, int_map from (select id, int_map from complextypestbl) s;
---- RESULTS
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
---- TYPES
bigint,string
====
---- QUERY
with s as (select id, t.int_map from complextypestbl t)
select id, int_map from s;
---- RESULTS
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
---- TYPES
bigint,string
====
---- QUERY
select id, int_map from complextypes_maps_view;
---- RESULTS
1,'{"k1":1,"k2":100}'
2,'{"k1":2,"k2":null}'
3,'{}'
4,'{}'
5,'{}'
6,'NULL'
7,'{"k1":null,"k3":null}'
8,'{"k1":-1}'
---- TYPES
bigint,string
====
---- QUERY
# Unnesting map returned by view.
select id, m.key, m.value from complextypes_maps_view v, v.int_map m;
---- RESULTS
1,'k1',1
1,'k2',100
2,'k1',2
2,'k2',NULL
7,'k1',NULL
7,'k3',NULL
8,'k1',-1
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned from WITH clause and predicate in inner query.
with v as (select id, int_map from complextypestbl where id=1)
select v.id, a.key, a.value from v, v.int_map a;
---- RESULTS
1,'k1',1
1,'k2',100
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned from WITH clause and predicate in outer query.
with v as (select id, int_map from complextypestbl)
select v.id, a.key, a.value from v, v.int_map a where id=1;
---- RESULTS
1,'k1',1
1,'k2',100
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned from WITH clause on item.
with v as (select id, int_map from complextypestbl)
select v.id, a.key, a.value from v, v.int_map a where a.key='k1'
---- RESULTS
1,'k1',1
2,'k1',2
7,'k1',NULL
8,'k1',-1
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned by view wrapped in inline view.
select v.id, a.key, a.value from
(select id, int_map from complextypes_maps_view) v, v.int_map a;
---- RESULTS
1,'k1',1
1,'k2',100
2,'k1',2
2,'k2',NULL
7,'k1',NULL
7,'k3',NULL
8,'k1',-1
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned by view wrapped in inline view + WITH clause.
with v2 as (select id, int_map from complextypes_maps_view)
select v.id, a.key, a.value from (select id, int_map from v2) v, v.int_map a;
---- RESULTS
1,'k1',1
1,'k2',100
2,'k1',2
2,'k2',NULL
7,'k1',NULL
7,'k3',NULL
8,'k1',-1
---- TYPES
bigint,string,int
====
---- QUERY
# Unnesting map returned by view wrapped in inline view + WITH clause.
with v2 as (select id, int_map from complextypes_maps_view)
select v.id, a.key, a.value from
(select id, int_map from v2 where id=1) v, v.int_map a
where a.key='k1';
---- RESULTS
1,'k1',1
---- TYPES
bigint,string,int
====
---- QUERY
select item from unnest(complextypestbl.int_map_array)
---- RESULTS
'{"k1":1}'
'{"k3":null,"k1":1}'
'NULL'
'{}'
'NULL'
'NULL'
'{}'
'{"k1":1}'
'{}'
'{}'
---- TYPES
string
====
---- QUERY
select id, a.key, a.value from complextypes_maps_view t left join t.int_map a;
---- RESULTS
1,'k1',1
1,'k2',100
2,'k1',2
2,'k2',NULL
3,'NULL',NULL
4,'NULL',NULL
5,'NULL',NULL
6,'NULL',NULL
7,'k1',NULL
7,'k3',NULL
8,'k1',-1
---- TYPES
BIGINT,STRING,INT
====
---- QUERY
select id, a2.key, a2.value from complextypes_maps_view v, v.int_map_array a1, a1.item a2;
---- RESULTS
1,'k1',1
2,'k3',NULL
2,'k1',1
8,'k1',1
---- TYPES
BIGINT,STRING,INT
====
---- QUERY
# Regression test for:
# IMPALA-11434: "More than 1 2d arrays in select list causes analysis error"
select id, map_1d, map_2d, map_3d, arr_int_3d, map_map_array from collection_tbl;
---- RESULTS
1,'{1:"first",2:"second"}','{1:{10:"ten",20:"twenty"},2:{30:"thirty",40:"forty"}}','{1:{10:{100:"hundred",200:"two hundred"},20:{300:"three hundred",400:"four hundred"}},2:{30:{500:"five hundred",600:"six hundred"},40:{700:"seven hundred",800:"eight hundred"}}}','[[[1,2,null],[3]],[[4]]]','{1:{10:[100,200],20:[300,400]},2:{30:[500,600],40:[700,800]}}'
---- TYPES
INT,STRING,STRING,STRING,STRING,STRING
=====
---- QUERY
select id, map_1d, map_2d, mma.value mma_value, ma.value ma_value
from collection_tbl c, c.map_map_array mma, mma.value ma;
---- RESULTS
1,'{1:"first",2:"second"}','{1:{10:"ten",20:"twenty"},2:{30:"thirty",40:"forty"}}','{10:[100,200],20:[300,400]}','[100,200]'
1,'{1:"first",2:"second"}','{1:{10:"ten",20:"twenty"},2:{30:"thirty",40:"forty"}}','{10:[100,200],20:[300,400]}','[300,400]'
1,'{1:"first",2:"second"}','{1:{10:"ten",20:"twenty"},2:{30:"thirty",40:"forty"}}','{30:[500,600],40:[700,800]}','[500,600]'
1,'{1:"first",2:"second"}','{1:{10:"ten",20:"twenty"},2:{30:"thirty",40:"forty"}}','{30:[500,600],40:[700,800]}','[700,800]'
---- TYPES
INT,STRING,STRING,STRING,STRING
=====
---- QUERY
-- Test that map keys are printed correctly.
set CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS=1;
select
map_bool_key,
map_tinyint_key,
map_smallint_key,
map_bigint_key,
map_float_key,
map_double_key,
map_decimal_key,
map_string_key,
map_char_key,
map_varchar_key,
map_timestamp_key,
map_date_key
from collection_tbl;
---- RESULTS
'{true:"true",false:"false"}','{-1:"a",0:"b",1:"c"}','{-1:"a",0:"b",1:"c"}','{-1:"a",0:"b",1:"c"}','{-1.5:"a",0.25:"b",1.75:"c"}','{-1.5:"a",0.25:"b",1.75:"c"}','{-1.8:"a",0.2:"b",1.2:"c"}','{"one":1,"two":2,"three":3}','{"Mon":1,"Tue":2,"Wed":3,"Thu":4,"Fri":5,"Sat":6,"Sun":7}','{"a":"A","ab":"AB","abc":"ABC"}','{"2022-12-10 08:15:12":"Saturday morning","2022-12-09 18:15:12":"Friday evening"}','{"2022-12-10":"Saturday","2022-12-09":"Friday"}'
---- TYPES
STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
=====
---- QUERY
-- Test that map keys are printed correctly with STRINGIFY_MAP_KEYS=true.
set CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS=1;
set STRINGIFY_MAP_KEYS=1;
select
map_bool_key,
map_tinyint_key,
map_smallint_key,
map_bigint_key,
map_float_key,
map_double_key,
map_decimal_key,
map_string_key,
map_char_key,
map_varchar_key,
map_timestamp_key,
map_date_key
from collection_tbl;
---- RESULTS
'{"true":"true","false":"false"}','{"-1":"a","0":"b","1":"c"}','{"-1":"a","0":"b","1":"c"}','{"-1":"a","0":"b","1":"c"}','{"-1.5":"a","0.25":"b","1.75":"c"}','{"-1.5":"a","0.25":"b","1.75":"c"}','{"-1.8":"a","0.2":"b","1.2":"c"}','{"one":1,"two":2,"three":3}','{"Mon":1,"Tue":2,"Wed":3,"Thu":4,"Fri":5,"Sat":6,"Sun":7}','{"a":"A","ab":"AB","abc":"ABC"}','{"2022-12-10 08:15:12":"Saturday morning","2022-12-09 18:15:12":"Friday evening"}','{"2022-12-10":"Saturday","2022-12-09":"Friday"}'
---- TYPES
STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
=====