How can I convert array to string in hive sql?

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

I want to convert an array to string in hive. I want to collect_set array values to convert to string without [[""]].

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

so that [["2016-07-01", "2016-07-02"]] would become 2016-07-01, 2016-07-02

回答1:

Use concat_ws(string delimiter, array<string>) function to concatenate array:

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

If the date field is not string, then convert it to string:

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!