Hive 的collect_set使用详解

Posted wingler

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hive 的collect_set使用详解相关的知识,希望对你有一定的参考价值。

Hive 的collect_set使用详解

  select a,collect_set(b) as bb from t where b<=‘xxxxxx‘ group by a

会按照a分组 通过collect_set会把每个a所对应的b构建成一个以逗号分隔的数组返回。上述SQL返回:

a1,["b1","b2"]

a2,["b1","b2","b3","b4"] 

 可以按照这个返回的数组做文章,即为

select * from (select a,collect_set(b) as bb from t where b<=‘xxxxxx‘ group by a)  where size(tmp.bb)=1 and tmp.bb[0]=‘xxxxxxxx‘;

表示某bb所对应的数组长度为1 并且第一个bb为xxxxxxxx的a

以上是关于Hive 的collect_set使用详解的主要内容,如果未能解决你的问题,请参考以下文章

大数据之Hive:Hive函数之collect_set()函数

使用 collect_set 进行 Hive 查询

hive中对多行进行合并—collect_set&collect_list函数

Hive相关

Hive / ClickHouse 行转列函数 collect_set() / groupUniqArray()

hive排序后collect_set