hive中实现相似MySQL中的group_concat功能

博客搬家了,欢迎你们关注,https://bobjin.com
Sql代码
  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中,可用:sql

 

SELECT id,
concat_ws('|', collect_set(str)) 
FROM t  
GROUP BY id;函数

获得结果:spa

 

1 A|Bget

2 C|D博客

 

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

博客搬家了,欢迎你们关注,https://bobjin.comclass

相关文章
相关标签/搜索