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
posted @   凌羽  阅读(25867)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示