码迷,mamicode.com
首页 > 其他好文 > 详细

Hive中实现group concat功能(不用udf)

时间:2018-08-31 11:42:47      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:ken   不用   ted   nbsp   不容易   string   udf   class   sel   

在 Hive 中实现将一个字段的多条记录拼接成一个记录:

 1 hive> desc t;  
 2 OK  
 3 id      string  
 4 str     string  
 5 Time taken: 0.249 seconds  
 6 hive> select * from t;  
 7 OK  
 8 1       A  
 9 1       B  
10 2       C  
11 2       D  
12 Time taken: 0.209 seconds 

 

在Hive0.9中,可用:

SELECT id,
concat_ws(‘|‘, collect_set(str)) 
FROM t  
GROUP BY id;

得到结果:

 

1 A|B

2 C|D

 

但在hive0.7中不容易实现,concat_ws函数不支持Array。

 

Hive中实现group concat功能(不用udf)

标签:ken   不用   ted   nbsp   不容易   string   udf   class   sel   

原文地址:https://www.cnblogs.com/shujuxiong/p/9564556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!