hive str_to_map 的使用

hive str_to_map 的使用

    • 官方介绍
    • 案例

官方介绍

map str_to_map(text[, delimiter1, delimiter2]) Splits text into key-value pairs using two delimiters. Delimiter1 separates text into K-V pairs, and Delimiter2 splits each K-V pair. Default delimiters are ‘,’ for delimiter1 and ‘=’ for delimiter2. 将字符串str按照指定分隔符转换成Map,第一个参数是需要转换字符串,第二个参数是键值对之间的分隔符,默认为逗号;第三个参数是键值之间的分隔符,默认为"="

案例

 select str_to_map('name:奥特曼&age:22','&') 

结果

  {"name":"奥特曼","age":"22"}

with result_data as (
select 
     str_to_map(concat_ws(',',collect_set(concat_ws(':',id_type,id)))) as reuslt_map ,status
from
dw_id_mapping
group by status
)

select
nvl(reuslt_map['mac'],''),
nvl(reuslt_map['imei'],''),
nvl(reuslt_map['imeimd514'],''),
nvl(reuslt_map['imeimd515'],''),
nvl(reuslt_map['idfa'],''),
nvl(reuslt_map['androidid'],''),
status
from
result_data

你可能感兴趣的:(hive,hive)