9

I have a table like the following :

User:String Alias:String
JohnDoe     John
JohnDoe     JDoe
Roger       Roger

And I would like to group all the aliases of an user in an array, in a new table which would look like this :

User:String Alias:array<String>
JohnDoe     [John, JDoe]
Roger       [Roger]

I can't figure out how to do that with HiveQL.Do I have to write an UDF for that ?

Thanks !

C4stor
  • 8,355
  • 6
  • 29
  • 47

1 Answers1

16

Check out the built-in aggregate function collect_set.

select 
    User, 
    collect_set(Alias) as Alias
from table
group by User;
Lukas Vermeer
  • 5,920
  • 2
  • 16
  • 19