1.数组 arrays
arrays: ARRAY<data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)
建表
create table t_movie(moive_name string,actors array<string>,first_show date)
row format delimited fields terminated by ','
collection items terminated by ':'; # 设置array里的分隔符
查询
select * from t_movie;
select moive_name,actors[0] from t_movie; # 索引数组中某个位置的值
select moive_name,actors from t_movie where array_contains(actors,'吴刚'); # array_contains方法判断数组是否包含
select moive_name,size(actors) from t_movie; # size计算array的大小
2.字典 map
maps: MAP<primitive_type, data_type> (Note: negative values and non-constant expressions are allowed as of Hive 0.14.)
建表
create table t_person(id int,name string,family_members map<string,string>,age int)
row format delimited fields terminated by ','
collection items terminated by '#'
map keys terminated by ':';
查询
select id,name,family_members['father'] as father from t_person; # 查看字典某个key的value
select id,name,map_keys(family_members) as relation from t_person; # 查看所有key
select id,name,map_values(family_members) from t_person; # 查看所有values
select id,name,map_values(family_members)[0] from t_person; # 查看某个vaule
3.结构struct
structs: STRUCT<col_name : data_type, ...>
建表
create table t_person_struct(id int,name string,info struct<age:int,sex:string,addr:string>)
row format delimited fields terminated by ','
collection items terminated by ':';
查询
select * from t_person_struct;
select id,name,info.age from t_person_struct;