Hive 中的 COLLECT

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

有没有办法将重复项保留在 Hive 中的收集集中,或者使用其他方法模拟 Hive 提供的那种聚合集合?我想将列中具有相同键的所有项目聚合到一个数组中,并带有重复项.

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.

即:

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 Array<int>(4,4,2) fkjh43f Array<int>(1,8,8) rjkhd93 Array<int>(7,4,7)

推荐答案

Hive 0.13.0 后尝试使用 COLLECT_LIST(col)

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:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616190.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Hive   COLLECT

发布评论

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

>www.elefans.com

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