How can I convert array to string in hive sql?

只愿长相守 提交于 2019-12-30 02:39:07

问题


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)))

Read also this answer about alternative ways if you already have an array and do not want to explode it: How to concatenate the elemets of int array to string in Hive



来源:https://stackoverflow.com/questions/38711201/how-can-i-convert-array-to-string-in-hive-sql

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