Hive : Concat a map

感情迁移 提交于 2020-01-06 13:50:30

问题


I have a small trouble into Hive, when I try to concatenate map

Assume that I've something like that :

var 1 | var 2

x | map(key1:value1)

x | map(key2:value2)

x | map(key3:value3)

y | map(key4:value4)

What I'am trying to get, It's something like that

var 1 | var 2

x | map(key1:value1 ; key2:value2; key3:value3)

y | map(key4,value4)

Something like a map concatenation.

How can I proceed whith Hive ?


回答1:


Use this Query...

select var1,collect_set(CONCAT_WS(',',map_keys(var2),map_values(var2))) as var2 from example group by var1;

This will get you output like this...

var1 | var2

x | ["key1,value1","key2,value2","key3,value3"]

y | ["key4,value4"]



来源:https://stackoverflow.com/questions/26723159/hive-concat-a-map

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!