hive 高级结构

•array类型访问: A[n]
•map类型访问: M[key]
•struct类型访问: S.x
•  array 类型访问 : A[n]
语法: A[n]
操作类型: A为array类型,n为int类型
说明:返回数组A中的第n个变量值。数组的起始下标为0。比如,A是个值为['foo', 'bar']的数组类型,那么A[0]将返回'foo',而A[1]将返回'bar'
举例:
hive> create table alex_test as select array("tom","mary","tim") as t from dual;
hive> select t[0],t[1],t[2] from alex_test;
tom     mary    tim
•  map 类型访问 : M[key]
语法: M[key]
操作类型: M为map类型,key为map中的key值
说明:返回map类型M中,key值为指定值的value值。比如,M是值为{'f' -> 'foo', 'b' -> 'bar', 'all' -> 'foobar'}的map类型,那么M['all']将会返回'foobar'
举例:
hive> Create table alex_test as select map('100','tom','200','mary') as t from dual;
hive> select t['200'],t['100'] from alex_test;
mary    tom
•  struct 类型访问 : S.x
语法: S.x
操作类型: S为struct类型
说明:返回结构体S中的x字段。比如,对于结构体struct foobar {int foo, int bar},foobar.foo返回结构体中的foo字段
举例:
hive> create table alex_test as select struct('tom','mary','tim') as t from dual;
hive> describe alex_test;
t       struct<col1:string,col2:string,col3:string>
hive> select t.col1,t.col3 from alex_test;
tom     tim
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值