I'm trying to convert some Python code to Scala.
Python code:
def col_c(o_row_ids,n_row_ids):
o_set=set(o_row_ids)
n_set=set(n_row_ids)
if o_set=n_set
return "in"
elif o_set < n_set:
return "Me"
elif n_set < o_set:
return "Sp"
return "SM"
Scala code:
def col_c: UserDefinedFunction = udf((o_row_ids:Seq[String], n_row_ids: Seq[String]) => {
val o_set = o_row_ids.toSet.count(z => true) //set(o_row_ids)
val n_set = n_row_ids.toSet.count(z=> true)
if (o_set == n_set)
"In"
else if( o_set < n_set)
"Me"
else if (n_set < o_set)
"Sp"
else "SM"
})
But I'm getting the following error:
failed to execute user defined function(col_c(array(string),array(string)=>string scala.collection.mutable.wrappedArray$ofRef cannot be cast to scala .collection.immutable.Seq
Any suggestion how to prevent this error?
WrappedArrayextendsscala.collection.mutable.Seqwhich itself extendsscala.collection.Seq.Looks like you have imported
scala.collection.immutable.Seq, thus the error.One possibility to solve your issue is to type your UDF with inputs as
scala.collection.Seq.