0%

查询map字段

查询map字段

建表语句

1
2
3
4
5
create table test_map(name string, score map<string,int>)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY ':'

Collection Functions

The following built-in collection functions are supported in Hive:

返回类型 函数 描述
int size(Map<K.V>) 返回map的元素数量
int size(Array) 返回数组的元素数量
array map_keys(Map<K.V>) 数组形式返回map中所有的key
array map_values(Map<K.V>) 数组形式返回map中所有的value
boolean array_contains(Array, value) 如果数组中包含该value则返回true
array sort_array(Array) 按照自然排序对数组进行排序

查询张三的成绩单中有数学的记录

1
select name,score from user_profile where name='张三' and array_contains(map_keys(score),'数学') limit 10;

欢迎关注我的其它发布渠道