Hive内置集合函数-size,map_keys,map_values,sort_array,array_contains

1. Hive内置Collection Functions

以下函数为Hive是提供的内置集合函数:

返回类型函数(签名)函数说明
intsize(Map<K.V>)Returns the number of elements in the map type.
intsize(Array)Returns the number of elements in the array type.
arraymap_keys(Map<K.V>)Returns an unordered array containing the keys of the input map.
arraymap_values(Map<K.V>)Returns an unordered array containing the values of the input map.
booleanarray_contains(Array, value)Returns TRUE if the array contains value.
arraysort_array(Array)Sorts the input array in ascending order according to the natural ordering of the array elements and returns it (as of version 0.9.0).

2. 测试Collection Functions

with tmp_map_data as (
    select map(
                   "k2", "v2", 
                   "k1", "v1", 
                   "k3", "v3"
           ) as m
    )
select
    size(m),								-- 3
    map_keys(m),							-- ["k1","k2","k3"]
    map_values(m),							-- ["v2","v1","v3"]
    sort_array(map_keys(m)),				-- ["k1","k2","k3"]
    array_contains(map_keys(m), 'k3'),		-- true
    array_contains(map_keys(m), 'k4')		-- false
from tmp_map_data;

3. 说明

Hive提供的内置集合函数, 在做一些集合内统计/查找/分析等场景下非常方便, 熟练使用, 可以极大的简化这类场景的开发.

参考文献:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值