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

参考文献:

相关推荐
B站计算机毕业设计超人13 天前
计算机毕业设计Django+Vue.js高考推荐系统 高考可视化 大数据毕业设计(源码+LW文档+PPT+详细讲解)
大数据·vue.js·hadoop·django·毕业设计·课程设计·推荐算法
B站计算机毕业设计超人13 天前
计算机毕业设计Django+Vue.js音乐推荐系统 音乐可视化 大数据毕业设计 (源码+文档+PPT+讲解)
大数据·vue.js·hadoop·python·spark·django·课程设计
十月南城13 天前
数据湖技术对比——Iceberg、Hudi、Delta的表格格式与维护策略
大数据·数据库·数据仓库·hive·hadoop·spark
王九思13 天前
Hive Thrift Server 介绍
数据仓库·hive·hadoop
土拨鼠烧电路13 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
Asher050913 天前
Hive核心知识:从基础到实战全解析
数据仓库·hive·hadoop
xhaoDream13 天前
Hive3.1.3 配置 Tez 引擎
大数据·hive·tez
yumgpkpm13 天前
AI视频生成:Wan 2.2(阿里通义万相)在华为昇腾下的部署?
人工智能·hadoop·elasticsearch·zookeeper·flink·kafka·cloudera
Asher050913 天前
Hadoop核心技术与实战指南
大数据·hadoop·分布式