map 结构
map 构造函数
语法:map(k1,v1,k2,v2,…)
操作类型:map
说明:使用给定的 key-value 对,构造一个 map 数据结构复制hive> select map('k1','v1','k2','v2') from iteblog;
OK
{"k2":"v2","k1":"v1"}复制hive> Create table iteblog as select map('100','tom','200','mary') as t from iteblog;
hive> describe iteblog;
t map<string ,string>
hive> select t from iteblog;
{"100":"tom","200":"mary"}复制获取 map 中的元素M[key]
语法:M[key]
操作类型:所有基础类型。M为map类型,key为map中的key值
说明:返回 map 结构 M 中 key 对应的 value,没有对应的 key 返回 NULL。
比如:M是值为{‘f’ -> ‘foo’, ‘b’ -> ‘bar’, ‘all’ -> ‘foobar’}的map类型,那么M[‘all’]将会返回’foobar’hive> select map('k1','v1','k2','v2')['k1'] from iteblog;
OK
v1
hive> select map('k1','v1','k2','v2')['k3'] from iteblog;
OK
NULL复制hive> Create table iteblog as select map('100','tom','200','mary') as t from iteblog;
hive> select t['200'],t['100'] from iteblog;
mary tom复制Map类型长度函数: size(Map
)
语法: size(Map)
返回值: int
说明: 返回map类型的长度hive> select size(map('100','tom','101','mary')) from iteblog;
2复制struct 结构
struct 构造函数
语法:struct(val1,val2,val3,…)
操作类型:struct
说明:使用给定的表达式,构造一个 struct 数据结构hive> select struct(1,'aaa',FALSE) from iteblog;
OK
{"col1":1,"col2":"aaa","col3":false}复制hive> create table iteblog as select struct('tom','mary','tim') as t from iteblog;
hive> describe iteblog;
t struct<col1:string ,col2:string,col3:string>
hive> select t from iteblog;
{"col1":"tom","col2":"mary","col3":"tim"}复制获取 struct 中的元素 S.x
语法:S.x
操作类型:所有类型。S为struct类型
说明:返回 struct 结构 S 中名为 x 的元素。
比如:对于结构体struct foobar {int foo, int bar},foobar.foo返回结构体中的foo字段hive> select named_struct('a',1,'b','aaa','c',FALSE).c from iteblog;
OK
false复制hive> create table iteblog as select struct('tom','mary','tim') as t from iteblog;
hive> describe iteblog;
t struct<col1:string ,col2:string,col3:string>
hive> select t.col1,t.col3 from iteblog;
tom tim复制array 结构
array 构造函数
语法:array(val1,val2,val3,…)
操作类型:array
说明:使用给定的表达式,构造一个 array 数据结构hive> select array(1,2,3) from iteblog;
OK
[1,2,3]复制hive> create table iteblog as select array("tom","mary","tim") as t from iteblog;
hive> describe iteblog;
t array<string>
hive> select t from iteblog;
["tom","mary","tim"]复制获取 array 中的元素 A[n]
语法:A[n]
操作类型:所有基础类型
说明:返回数组 A 中第 n 个索引的元素值,数组的起始下标为0。
比如:A是值为[‘foo’, ‘bar’]的数组类型,那么A[0]将返回’foo’,而A[1]将返回’bar’hive> select array('a','b','c')[1] from iteblog;
OK
b复制hive> create table iteblog as select array("tom","mary","tim") as t from iteblog;
hive> select t[0],t[1],t[2] from iteblog;
tom mary tim复制array类型长度函数: size(Array
)
语法: size(Array)
返回值: int
说明: 返回array类型的长度hive> select size(array('100','101','102','103')) from iteblog;
4复制named_struct 结构
语法:named_struct(name1,val1,name2,val2,name3,val3,…)
操作类型:struct
说明:使用给定的表达式,构造一个指定列名的 struct 数据结构hive> select named_struct('a',1,'b','aaa','c',FALSE) from iteblog;
OK
{"a":1,"b":"aaa","c":false}复制create_union
语法:create_union (tag, val1, val2, …)
操作类型:uniontype
说明:使用给定的 tag 和表达式,构造一个 uniontype 数据结构。tag 表示使用第 tag 个
表达式作为 uniontype 的 valuehive> select create_union(0,'ss',array(1,2,3)) from iteblog;
OK
{0:"ss"}
hive> select create_union(1,'ss',array(1,2,3)) from iteblog;
OK
{1:[1,2,3]}
hive> select create_union(1,'ss',array(1,2,3),'aa') from iteblog;
OK
{2:'aa'}复制
文章转载自Java菜鸟,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
【专家观点】罗敏:从理论到真实SQL,感受DeepSeek如何做性能优化
墨天轮编辑部
1179次阅读
2025-03-06 16:45:38
【专家有话说第五期】在不同年龄段,DBA应该怎样规划自己的职业发展?
墨天轮编辑部
1149次阅读
2025-03-13 11:40:53
2025年2月国产数据库大事记
墨天轮编辑部
891次阅读
2025-03-05 12:27:34
2025年2月国产数据库中标情况一览:GoldenDB 3500+万!达梦近千万!
通讯员
795次阅读
2025-03-06 11:40:20
2月“墨力原创作者计划”获奖名单公布
墨天轮编辑部
409次阅读
2025-03-13 14:38:19
AI的优化能力,取决于你问问题的能力!
潇湘秦
390次阅读
2025-03-11 11:18:22
优炫数据库成功应用于国家电投集团青海海南州新能源电厂!
优炫软件
325次阅读
2025-03-21 10:34:08
达梦数据与法本信息签署战略合作协议
达梦数据
270次阅读
2025-03-06 09:26:57
国产化+性能王炸!这套国产方案让 3.5T 数据 5 小时“无感搬家”
YMatrix
253次阅读
2025-03-13 09:51:26
IBM收购数据库厂商DataStax:瞄准向量和AI搜索
深度数据云
249次阅读
2025-02-28 12:04:04