string to map

该文讲述了在Hive查询中,如何通过`concat_ws`函数组合字段b和c的值,利用`collect_set`消除重复,然后将结果转化为字符串,最后用`str_to_map`函数将字符串转换为Map结构。这种方法常用于聚合数据并构建复杂的数据结构。
摘要由CSDN通过智能技术生成
select pcgid as gid,str_to_map(concat_ws(",",collect_set(concat_ws(':', mobilegid, cast(value as string)) ))) as gids,count(1) as num
from result_pair group by pcgid;
group by a的时候,如何把字段b,c变成一个map,有个str_to_map的函数,可以先把b,c连接成为一个字符串,在把整个set的结果连接成一个字符串,最后再用str_to_map

concat_ws

desc function concat_ws;
concat_ws(separator, [string | array(string)]+) - returns the concatenation of the strings separated by the separator.


collect_set

hive> desc function collect_set;
collect_set(x) - Returns a set of objects with duplicate elements eliminated

str_to_map:

hive> desc function str_to_map;
str_to_map(text, delimiter1, delimiter2) - Creates a map by parsing text 
hive> select str_to_map('a:b,d:c',',',':') ;
{"a":"b","d":"c"}
hive> select str_to_map('a:b,d:c') ;
{"a":"b","d":"c"}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值