Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create map group by a column in Hive

Tags:

join

hive

hiveql

I have a hive table like this :

colA    colB    colC
1       a       b
1       c       d
1       e       f
2       w       x
2       y       z

I want to create a map out of the colB and colC group by colA, like this:

colA      colMAP
1         {(a,b),(c,d),(e,f)}
2         {(w,x),(y,z)}

How can I achieve this in Hive.

like image 680
Abhinav Avatar asked Jan 30 '26 16:01

Abhinav


1 Answers

Try the following sql:

select c1, collect_list(map(c2,c3)) from T group by c1;

But the result is an array, not a map.

like image 160
StrongYoung Avatar answered Feb 02 '26 07:02

StrongYoung



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!