1
votes

I have a Spark dataframe with column that has array<struct<_1:long,_2:string>> datatype and following sample data:

WrappedArray([Value,Title1], [Value,Title2], [Value,Title3])

I want to convert this column from WrappedArray to a single String

Here is the desired output:

Value+Title1,Value+Title2,Value+Title3

I tried the following udf passing that column of the dataframe:

val f = (x:Seq[Row]) => x.mkString(",")
sqlContext.udf.register("f", f)

But the result is [Value,Title1],[Value,Title2],[Value,Title3]

1

1 Answers

3
votes

try this:

val f = (x:Seq[Row]) => x.map(row => "%s+%s".format(row.getString(0), 
row.getString(1))).mkString(",")