I have the following UDF:
val jac_index:(Array[String],Array[String])=>Float=(Sq1:Array[String],Sq2:Array[String])=>
{
val Sq3=Sq1.intersect(Sq2)
val Sq4=Sq1.union(Sq2).distinct
if (!Sq4.isEmpty) Sq3.length.toFloat/Sq4.length.toFloat else 0F
}
val jacUDF=udf(jac_index)
and when I execute the following sentence
val movie_jac_df=movie_pairs_df.withColumn("jac",jacUDF(movie_pairs_df("name"),movie_pairs_df("name2")))
I get the error "Failed to execute user defined function"
the schema of movie_pairs_df is the following
root
|-- movie: string (nullable = true)
|-- name: array (nullable = true)
| |-- element: string (containsNull = true)
|-- movie2: string (nullable = true)
|-- name2: array (nullable = true)
| |-- element: string (containsNull = true)
So what's the cause?