array
建表
create table stu_sub(id integer, subject string)
row format delimited fields terminated by '\t';
create table stu_subs(id integer, subjects array<string>)
row format delimited fields terminated by '\t'
collection items terminated by '|';
插入数据
insert into table stu_sub values(1001, 'java'),(1001, 'c++'),(1001,'python'),(1002,'c'),(1002,'html');
insert into table stu_sub values(1001, 'java'),(1001, 'c++'),(1001,'python'),(1002,'c'),(1002,'html');
第一种,collect_list(),集合不去重
insert into table stu_subs
select id, collect_list(subject) subjects from stu_sub group by id;
id |subjects |
1001|["java","c++","python","java","c++","python"]|
1002|["c","html","c","html"] |
第二种,collect_set(),集合去重
insert overwrite table stu_subs
select id, collect_set(subject) subjects