我如何可以将数组转换为hive sql中的字符串? [英] How can I convert array to string in hive sql?
本文介绍了我如何可以将数组转换为hive sql中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数组转换为配置单元中的字符串。我想collect_set数组值来转换为字符串,而不需要 [[]]
。
从actor_table group中选择actor,collect_set(date)as grpdate by actor;
使 [[2016-07-01,2016- 07-02]]
会变成 2016-07-01,2016-07-02
concat_ws(字符串分隔符,数组<字符串>)函数来连接数组:
从actor_table group by actor选择actor,concat_ws(',',collect_set(date))作为grpdate;
如果日期字段不是字符串,则将其转换为字符串:
concat_ws(',',collect_set(cast(date as string)))
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
解决方案
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)))
这篇关于我如何可以将数组转换为hive sql中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文