简体   繁体   English

wrappedArray$ofRef 无法转换为 scala.collection.immutable.Seq

[英]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.

相关问题 Spark java.lang.ClassCastException: scala.collection.mutable.WrappedArray 无法转换为 scala.collection.Seq.immutable - Spark java.lang.ClassCastException: scala.collection.mutable.WrappedArray cannot be cast to scala.collection.immutable.Seq 无法使用 mongodb 在 akka http 中将 scala.concurrent.impl.Promise$Transformation 转换为 scala.collection.immutable.Seq 错误? - Cannot cast scala.concurrent.impl.Promise$Transformation to scala.collection.immutable.Seq erro in akka http using mongodb? cas 异常:scala.collection.mutable.WrappedArray$ofRef 不能转换为 [D - cas Exception:scala.collection.mutable.WrappedArray$ofRef cannot be cast to [D Spark java.lang.ClassCastException:scala.collection.mutable.WrappedArray$ofRef 无法转换为 java.util.ArrayList - Spark java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to java.util.ArrayList 编译错误? java.lang.ClassCastException:scala.collection.mutable.WrappedArray $ ofRef无法强制转换为java.lang.Integer - Compiler bug? java.lang.ClassCastException: scala.collection.mutable.WrappedArray$ofRef cannot be cast to java.lang.Integer Scala + Spark - 如何从“scala.collection.mutable.WrappedArray$ofRef”转换为我们的自定义 object? - Scala + Spark - How to cast from 'scala.collection.mutable.WrappedArray$ofRef' to our custom object? 如何修复 scala 中的不匹配错误,其中发现:Seq[scala.collection.immutable.Seq required: scala.collection.Seq? - How can I fix mismatch error in scala where the found : Seq[scala.collection.immutable.Seq required: scala.collection.Seq? scala spark UDF ClassCastException: WrappedArray$ofRef 不能转换为 [Lscala.Tuple2 - scala spark UDF ClassCastException : WrappedArray$ofRef cannot be cast to [Lscala.Tuple2 scala编译错误:类型不匹配; found:需要IndexedSeq [Int]:scala.collection.immutable.Seq [Int] - scala compile error: type mismatch; found: IndexedSeq[Int] required: scala.collection.immutable.Seq[Int] 如何从 Java 中的 Java 列表创建 scala.collection.immutable.Seq? - How to create a scala.collection.immutable.Seq from a Java List in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM