struct 类似于java对象 pojo类
array 数组
map 键值对
创建集合数据类型的表
songsong,bingbing_lili,xiao song:18_xiaoxiao song:19,hui long guan_beijing
yangyang,caicai_susu,xiao yang:18_xiaoxiao yang:19,chao yang_beijing
create table tb_user(
name string,
friends array<string>,
children map<string,int>,
address struct<street:string,city:string>
)
row format delimited fields terminated by ',' ---信息的分割
collection items terminated by '_' ---集合之间的分割
map keys terminated by ':' ---map之间的切割
lines terminated by '\n';
load data local inpath '/data/user' into table tb_user;
-
数组取值
select name,friends[0] from tb_user;
-
查看集合长度
select name,size(friends) from tb_user;
select name,size(children) from tb_user;
-
根据key获取map的value值
select children['xiao song'] from tb_user where name = 'songsong';
-
获取map集合中所有的key
select
map_values(children)
from
tb_user;
-
获取map集合中所有的values
select
map_values(children)
from
tb_user;
-
炸裂map集合
select
name,
ch,
age
from
tb_user
lateral view explode(children) t as ch,age;
-
炸裂数组
select
name,
friend
from
tb_user
lateral view explode(friends)t as friend;
-
staruct 结构体获取属性
select
name,
address.street,
address.city
from
tb_user;