Abhinav
Abhinav

Reputation: 63

Create map group by a column in Hive

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.

Upvotes: 3

Views: 3474

Answers (1)

StrongYoung
StrongYoung

Reputation: 772

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.

Upvotes: 2

Related Questions