Hive中的COLLECT

编程入门 行业动态 更新时间:2024-10-19 16:38:26
本文介绍了Hive中的COLLECT_SET(),保持重复吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法将重复集合保存在Hive中的收集集合中,或者模拟Hive使用其他方法提供的聚合集合类型?我想将具有相同关键字的列中的所有项目汇总到一个数组中,并重复。

IE:

hash_id | num_of_cats ===================== ad3jkfk 4 ad3jkfk 4 ad3jkfk 2 fkjh43f 1 fkjh43f 8 fkjh43f 8 rjkhd93 7 rjkhd93 4 rjkhd93 7

应该返回:

hash_agg | cats_aggregate =========================== ad3jkfk数组< int>(4,4,2) fkjh43f数组< int>(1,8,8) rjkhd93数组< int>(7,4,7)

解决方案

尝试在Hive 0.13.0之后使用COLLECT_LIST(col)

SELECT hash_id,COLLECT_LIST(num_of_cats)AS aggr_set FROM 表名 WHERE blablabla GROUP BY hash_id ;

Is there a way to keep the duplicates in a collected set in Hive, or simulate the sort of aggregate collection that Hive provides using some other method? I want to aggregate all of the items in a column that have the same key into an array, with duplicates.

I.E.:

hash_id | num_of_cats ===================== ad3jkfk 4 ad3jkfk 4 ad3jkfk 2 fkjh43f 1 fkjh43f 8 fkjh43f 8 rjkhd93 7 rjkhd93 4 rjkhd93 7

should return:

hash_agg | cats_aggregate =========================== ad3jkfk Array<int>(4,4,2) fkjh43f Array<int>(1,8,8) rjkhd93 Array<int>(7,4,7)

解决方案

Try to use COLLECT_LIST(col) after Hive 0.13.0

SELECT hash_id, COLLECT_LIST(num_of_cats) AS aggr_set FROM tablename WHERE blablabla GROUP BY hash_id ;

更多推荐

Hive中的COLLECT

本文发布于:2023-11-22 05:45:35,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Hive   COLLECT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!