Hive內嵌集合函數:size,map_keys,map_values,array_contains,sort_array等詳解

0.hive官方函數解釋

       hive官網函數大全地址:HIVE官網函數大全地址

Collection Functions

Return Type

Name(Signature)

Description

int

size(Map<K.V>)

Returns the number of elements in the map type.

int

size(Array<T>)

Returns the number of elements in the array type.

boolean

array_contains(Array<T>, value)

Returns TRUE if the array contains value.

array<V>

map_values(Map<K.V>)

Returns an unordered array containing the values of the input map.

array<t>

sort_array(Array<T>)

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).

array<K>

map_keys(Map<K.V>)

Returns an unordered array containing the keys of the input map.

1.使用演示

1.1數據展示,手動生成map類型數據

 select 
str_to_map(concat(path_id,':',filter_name ))   ---是map類型的
from FDM_SOR.T_FIBA_MULTI_UBA_CFG_PATH_DETAIL_D 
group by path_id,filter_Name 

1.2函數測試

select 
size(m),  --求map的長度
map_keys(m), --將map中對應的所有keys.存儲格式爲array
map_values(m),  --將map中對應的所有values
sort_array(map_keys(m)),  --對map的keys進行排序
array_contains(map_keys(m),'162')  ---map的keys中是否包含162
from ( select 
str_to_map(concat(path_id,':',filter_name )) m   ---是map類型的
from FDM_SOR.T_FIBA_MULTI_UBA_CFG_PATH_DETAIL_D 
group by path_id,filter_Name ) a

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章