1
votes

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

WrappedArray([Book1,Title1], [Book2,Title2], [Book3,Title3])

I want to convert this column from WrappedArray of tuples to a string

Here is the desired output:

Book1/Title1 Book2/Title2 Book3/Title3

I tried the following udf passing that column of the dataframe, but it did not work:

val unwraparr = udf ((x: mutable.WrappedArray[(String, String)]) => x.map { case (val1, val2) => val1 + "/" + val2 })
1

1 Answers

1
votes

Try like this:

import org.apache.spark.sql.Row

(x: Seq[Row]) => x.map { case Row(val1: String, val2: String) => val1 + "/" + val2 })