问题
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