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

参考文献:

相关推荐
yumgpkpm1 天前
数据可视化AI、BI工具,开源适配 Cloudera CMP 7.3(或类 CDP 的 CMP 7.13 平台,如华为鲲鹏 ARM 版)值得推荐?
人工智能·hive·hadoop·信息可视化·kafka·开源·hbase
二进制_博客1 天前
使用datax将mysql数据抽取到hive分区表无数据
数据库·hive·mysql
干就完事了1 天前
Hive视图
数据仓库·hive·hadoop
Linux Huang1 天前
【Dinky】IDEA运行出现HistoryServer异常
java·hadoop·flink·intellij idea
A尘埃1 天前
Hive基于Hadoop的数据仓库工具
数据仓库·hive·hadoop
Macbethad2 天前
使用WPF编写一个多维度伺服系统的程序
大数据·hadoop·wpf
百***35942 天前
从0到1部署Tomcat和添加servlet(IDEA2024最新版详细教程)
hive·servlet·tomcat
howard20052 天前
5.2 Hive插入数据实战
hive·插入数据
杂家2 天前
Hive on Spark && Spark on Hive配置
大数据·数据仓库·hive·hadoop·spark
沧海寄馀生2 天前
Apache Hadoop生态组件部署分享-Hadoop
大数据·hadoop·分布式·apache