如何在hive sql中将数组转换为字符串?

时间:2016-08-02 03:12:44

标签: arrays hive hiveql

我想在hive中将数组转换为字符串。我想将collect_set数组值转换为不带[[""]]的字符串。

select actor, collect_set(date) as grpdate from actor_table group by actor;

以便[["2016-07-01", "2016-07-02"]]成为2016-07-01, 2016-07-02

1 个答案:

答案 0 :(得分:32)

使用concat_ws(string delimiter, array<string>)函数连接数组:

select actor, concat_ws(',',collect_set(date)) as grpdate from actor_table group by actor;

如果日期字段不是字符串,则将其转换为字符串:

concat_ws(',',collect_set(cast(date as string)))