hive复杂类型访问操作

发布时间:2020-03-30 17:26:26 作者:超人学院66
来源:网络 阅读:319

复杂类型访问操作1. array类型访问: A[n]

语法: A[n]

操作类型: A为array类型,n为int类型

说明:返回数组A中的第n个变量值。数组的起始下标为0。比如,A是个值为['foo', 'bar']的数组类型,那么A[0]将返回'foo',而A[1]将返回'bar'

举例:

hive> create table lxw_test as selectarray("tom","mary","tim") as t from lxw_dual;

hive> select t[0],t[1],t[2] from lxw_test;

tom     mary    tim

2. 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 lxw_test as selectmap('100','tom','200','mary') as t from lxw_dual;

hive> select t['200'],t['100'] from lxw_test;

mary    tom

3. struct类型访问: S.x

语法: S.x

操作类型: S为struct类型

说明:返回结构体S中的x字段。比如,对于结构体struct foobar {int foo, int bar},foobar.foo返回结构体中的foo字段

举例:

hive> create table lxw_test as select struct('tom','mary','tim')as t from lxw_dual;

hive> describe lxw_test;

t      struct<col1:string,col2:string,col3:string>

hive> select t.col1,t.col3 from lxw_test;

tom     tim

更多精彩内容请关注:http://bbs.superwu.cn 

关注超人学院微信二维码:hive复杂类型访问操作

推荐阅读:
  1. Hive基本操作
  2. hive的数据类型

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

hadoop hive 吴超hadoop

上一篇:CentOS 7 引导过程介绍

下一篇:linux保存vi编辑后的文件的方法

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》