Hive的collect_set使⽤详解Hive 的collect_set使⽤详解
blog.csdn/liyantianmin/article/details/48262109
1. 对于⾮group by字段,可以⽤Hive的collect_set函数收集这些字段,返回⼀个数组;
2. 使⽤数字下标,可以直接访问数组中的元素;
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"]
hive 字符串转数组
可以按照这个返回的数组做⽂章,即为
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

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。