Hive中實現group concat功能(不用udf)
Sql代碼
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。