如何将字符串数组的列转换为字符串?
问题描述:
我有一个列,在火花表中该列的类型为array < string >
.我正在使用SQL查询这些火花表.我想将array < string >
转换为string
.
I have a column, which is of type array < string >
in spark tables. I am using SQL to query these spark tables. I wanted to convert the array < string >
into string
.
使用以下语法时:
select cast(rate_plan_code as string) as new_rate_plan from
customer_activity_searches group by rate_plan_code
rate_plan_code
列具有以下值:
["AAA","RACK","SMOBIX","SMOBPX"]
["LPCT","RACK"]
["LFTIN","RACK","SMOBIX","SMOBPX"]
["LTGD","RACK"]
["RACK","LEARLI","NHDP","LADV","LADV2"]
以下内容填充在new_rate_plan
列中:
org.apache.spark.sql.catalyst.expressions.UnsafeArrayData@e4273d9f
org.apache.spark.sql.catalyst.expressions.UnsafeArrayData@c1ade2ff
org.apache.spark.sql.catalyst.expressions.UnsafeArrayData@4f378397
org.apache.spark.sql.catalyst.expressions.UnsafeArrayData@d1c81377
org.apache.spark.sql.catalyst.expressions.UnsafeArrayData@552f3317
当我将decimal
转换为int
或int
转换为double
时,
投射似乎起作用,但是在这种情况下不起作用.好奇为什么演员表不能在这里工作. 非常感谢您的帮助.
Cast seem to work when I am converting decimal
to int
or int
to double
, but not in this case. Curious why the cast is not not working here.
Greatly appreciate your help.
答
在Spark 2.1+中,要在单个Array列中进行值的串联,可以使用以下命令:
In Spark 2.1+ to do the concatenation of the values in a single Array column you can use the following:
-
concat_ws
标准功能 -
map
运算符 - 用户定义的函数(UDF)
-
concat_ws
standard function -
map
operator - a user-defined function (UDF)