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

参考文献:

相关推荐
java_logo21 小时前
Docker 部署 Hue:轻松搭建数据库与数据仓库 SQL 查询平台
数据库·数据仓库·sql·docker·hue·部署教程·轩辕镜像
Francek Chen1 天前
【大数据处理与分析】数据仓库Hive:08 Impala
数据仓库·hive·hadoop·数据分析·impala
A smirK squirrel1 天前
Windows环境下Minio本地安装部署
数据仓库
ha_lydms2 天前
Window Functions(窗口函数)
大数据·数据仓库·hadoop·spark·数据处理·dataworks·maxcompute
geovindu2 天前
sql:Managing Complex Joins and Subqueries in SQL using mysql 9.0
大数据·数据库·数据仓库·sql·mysql·数据库开发·数据库架构
zhangzeyuaaa2 天前
StarRocks 的技术版图:在分析、检索与流处理之间找到位置
大数据·数据仓库
大鳥2 天前
JSON 解析最佳实践:从入门到生产级优化
hive·sql·spark·json
geovindu2 天前
sql:SQL Views and Materialized Views using mysql 9.0
大数据·数据库·数据仓库·sql·mysql·数据库开发·数据库架构
ha_lydms2 天前
Xml Functions(XML 函数)
xml·大数据·hadoop·spark·数据处理·dataworks·maxcompute
ha_lydms2 天前
Vector Functions(向量函数)
大数据·hadoop·spark·数据处理·dataworks·maxcompute·数据中台