Spark UDF for StructType / Row : <p>I have a "StructType" column in spark Dataframe that has an array and a string as sub-fields. I'd like to modify the array and return the new column of the same type. Can I process it with UDF? Or what are the alternatives?</p>

<pre><code>import org.apache.spark.sql.types._
import org.apache.spark.sql.Row
val sub_schema = StructType(StructField("col1",ArrayType(IntegerType,false),true) :: StructField("col2",StringType,true)::Nil)
val schema = StructType(StructField("subtable", sub_schema,true) :: Nil)
val data = Seq(Row(Row(Array(1,2),"eb")),  Row(Row(Array(3,2,1), "dsf")) )
val rd = sc.parallelize(data)
val df = spark.createDataFrame(rd, schema)
df.printSchema

root
 |-- subtable: struct (nullable = true)
 |    |-- col1: array (nullable = true)
 |    |    |-- element: integer (containsNull = false)
 |    |-- col2: string (nullable = true)
</code></pre>

<p>It seems that I need a UDF of the type Row, something like </p>

<pre><code>val u =  udf((x:Row) =&gt; x)
       &gt;&gt; Schema for type org.apache.spark.sql.Row is not supported
</code></pre>

<p>This makes sense, since Spark does not know the schema for the return type.
Unfortunately, udf.register fails too: </p>

<pre><code>spark.udf.register("foo", (x:Row)=&gt; Row, sub_schema)
     &lt;console&gt;:30: error: overloaded method value register with alternatives: ...
</code></pre>
