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

hive> desc t;
OK
id      string
str     string
Time taken: 0.249 seconds
hive> select * from t;
OK
1       A
1       B
2       C
2       D
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。

猜你喜欢

转载自superlxw1234.iteye.com/blog/1886846