【发布时间】:2021-10-26 15:59:01
【问题描述】:
我正在尝试将一些 Python 代码转换为 Scala。
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 代码:
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"
})
但我收到以下错误:
执行用户定义失败 函数(col_c(数组(字符串),数组(字符串)=>字符串 scala.collection.mutable.wrappedArray$ofRef 不能转换为 scala .collection.immutable.Seq
有什么建议可以防止这个错误吗?
【问题讨论】:
标签: scala apache-spark pyspark user-defined-functions scala-collections