本文介绍了蜂巢:Concat一张地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图连接map时,我在Hive中遇到了一些麻烦。假设我有类似的东西:
$


b $ b

  var 1 | var 2 

x |地图(key1:value1)

x |地图(key2:value2)

x | map(key3:value3)

y | map(key4:value4)

我试图得到的东西就是这样

  var 1 | var 2 

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

y | map(key4,value4)

类似于地图拼接。



如何才能继续使用Hive?

解决方案

...



通过var1从示例组中选择var1,collect_set(CONCAT_WS(',',map_keys(var2),map_values(var2))) p>

这会让你得到像这样的输出......



var1 | var2



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

y | [key4,value4]


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 ?

解决方案

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"]

这篇关于蜂巢:Concat一张地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:45