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

参考文献:

相关推荐
一个数据大开发1 天前
大模型时代的数据中台架构演进:从数据仓库到认知引擎
数据仓库·架构
r-t-H1 天前
从零开始搭建CDH-第十二章
linux·hive·spark·centos·hbase
m0_639310792 天前
大数据技术原理-HDFS的安装与应用
java·大数据·jvm·hadoop·spring·hdfs·eclipse
188105069632 天前
摸鱼事务所——团队作业——大模型评测作业
大数据·hadoop·分布式
我思故我在78962 天前
hdfs文件系统
大数据·hadoop·hdfs
大连赵哥2 天前
分布式文件存储系统:Hadoop HDFS
hadoop·分布式·hdfs
王小王-1232 天前
基于Hadoop的服装电商数据分析系统【Hdfs、flume、HIve、sqoop、MySQL、echarts】
hive·hadoop·hdfs·服装电商分析·服装大数据
青春万岁!!2 天前
hiveSQL脚本性能优化-减少表扫描
大数据·hive·sql
这个DBA有点耶3 天前
数据迁移避坑指南:从Oracle到国产数据库的兼容性问题
数据库·数据仓库·sql·oracle·dba
灰太狼!!3 天前
数仓、接口开发常用clickhouses函数详解
数据仓库·sql·clickhouse