Hive-集合数据类型

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值