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

1. Hive内置Collection Functions

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

返回类型 函数(签名) 函数说明
int size(Map<K.V>) Returns the number of elements in the map type.
int size(Array) Returns the number of elements in the array type.
array map_keys(Map<K.V>) Returns an unordered array containing the keys of the input map.
array map_values(Map<K.V>) Returns an unordered array containing the values of the input map.
boolean array_contains(Array, value) Returns TRUE if the array contains value.
array sort_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

sql 复制代码
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提供的内置集合函数, 在做一些集合内统计/查找/分析等场景下非常方便, 熟练使用, 可以极大的简化这类场景的开发.

参考文献:

相关推荐
liupenglove7 小时前
自动驾驶数据仓库:时间片合并算法。
大数据·数据仓库·算法·elasticsearch·自动驾驶
吃手机用谁付的款20 小时前
基于hadoop的竞赛网站日志数据分析与可视化(下)
大数据·hadoop·python·信息可视化·数据分析
码字的字节1 天前
深入解析Hadoop RPC:技术细节与推广应用
hadoop·rpc
码字的字节1 天前
深入解析Hadoop架构设计:原理、组件与应用
大数据·hadoop·分布式·hadoop架构设计
LucianaiB2 天前
AI 时代的分布式多模态数据处理实践:我的 ODPS 实践之旅、思考与展望
大数据·数据仓库·人工智能·分布式·odps
༺水墨石༻2 天前
低版本hive(1.2.1)UDF实现清除历史分区数据
数据仓库·hive·hadoop
Leo.yuan3 天前
数据清洗(ETL/ELT)原理与工具选择指南:企业数字化转型的核心引擎
大数据·数据仓库·数据挖掘·数据分析·etl
isNotNullX3 天前
实时数仓和离线数仓还分不清楚?看完就懂了
大数据·数据库·数据仓库·人工智能·数据分析
熊猫钓鱼>_>3 天前
Hadoop 用户入门指南:驾驭大数据的力量
大数据·hadoop·分布式
William一直在路上3 天前
SpringBoot 拦截器和过滤器的区别
hive·spring boot·后端