[英]wrappedArray$ofRef cannot be cast to scala.collection.immutable.Seq
I'm trying to convert some Python code to Scala.我正在尝试将一些 Python 代码转换为 Scala。
Python code: Python 代码:
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: Scala 代码:
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无法执行用户定义的函数(col_c(array(string),array(string)=>string scala.collection.mutable.wrappedArray$ofRef 不能转换为 scala.collection.immutable.Seq
Any suggestion how to prevent this error?任何建议如何防止这个错误?
WrappedArray
extends scala.collection.mutable.Seq
which itself extends scala.collection.Seq
. WrappedArray
扩展scala.collection.mutable.Seq
本身扩展scala.collection.Seq
。
Looks like you have imported scala.collection.immutable.Seq
, thus the error.看起来您已经导入scala.collection.immutable.Seq
,因此出现了错误。
One possibility to solve your issue is to type your UDF with inputs as scala.collection.Seq
.解决您的问题的一种可能性是将您的 UDF 输入为scala.collection.Seq
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.