hive复合数据类型查表使用 以及控制语句 case when、if

–hive中的复合数据类型
–数组
–有如下数据
战狼2,吴京:吴刚:龙母,2017-08-16
三生三世十里桃花,刘亦菲:杨洋,2017-08-20
普罗米修斯,苍老师:小泽老师:波多老师,2017-09-17
–建表映射:

create table t_movie(movie_name string,actors array<string>,first_show date)
row format delimited fields terminated by ','
collection items terminated by ':';

–查询元素
select movie_name,actors[1],first_show from t_movie;
±------------±------±------------+
| movie_name | _c1 | first_show |
±------------±------±------------+
| 战狼2 | 吴刚 | 2017-08-16 |
| 三生三世十里桃花 | 杨洋 | 2017-08-20 |
| 普罗米修斯 | 小泽老师 | 2017-09-17 |

–查询包含字段

select movie_name,actors,first_show
from t_movie 
where array_contains(actors,'吴刚');

–查询每部电影有多少个演员

select movie_name,actors,first_show,size(actors) as actor_number
from t_movie;

–电影名字 主演数量 首映时间

select movie_name,size(actors) as actor_number,first_show
from t_movie;

二、–有如下数据

1,zhangsan,father:xiaoming#mother:xiaohuang#brother:xiaoxu,28
2,lisi,father:mayun#mother:huangyi#brother:guanyu,22
3,wangwu,father:wangjianlin#mother:ruhua#brother:jingtian,29
4,mayun,father:mayongzhen#mother:angelababy,26

建表映射

create table t_family(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 ':';

±-------------±---------------±---------------------------------------------------±------------- -+
| t_family.id | t_family.name | t_family.family_members | t_family.age |
±-------------±---------------±---------------------------------------------------±------------- -+
| 1 | zhangsan | {“father”:“xiaoming”,“mother”:“xiaohuang”,“brother”:“xiaoxu”} |

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值