Hadoop HIVE 复合数据类型

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;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值