1

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 Answer 1

3

try this:

val f = (x:Seq[Row]) => x.map(row => "%s+%s".format(row.getString(0), 
row.getString(1))).mkString(",")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.