问题
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 !
回答1:
Check out the built-in aggregate function collect_set.
select
User,
collect_set(Alias) as Alias
from table
group by User;
来源:https://stackoverflow.com/questions/16836702/grouping-hive-rows-in-an-array-of-this-rows