将这些行的数组中的配置单元行分组 [英] Grouping hive rows in an array of this rows
本文介绍了将这些行的数组中的配置单元行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
User:String别名:字符串
JohnDoe John
JohnDoe JDoe
Roger Roger
我想将用户的所有别名在数组中,在一个新的表中看起来像这样:
User:String别名:array< String>
JohnDoe [John,JDoe]
Roger [Roger]
如何使用HiveQL来做到这一点?我必须为此编写UDF吗?
谢谢!
解决方案
查看内置集合函数 collect_set
。
选择
User,
collect_set(Alias)作为别名
从表$ b $ group by User;
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 !
解决方案
Check out the built-in aggregate function collect_set
.
select
User,
collect_set(Alias) as Alias
from table
group by User;
这篇关于将这些行的数组中的配置单元行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文