gpt4 book ai didi

scala - 将函数传递给 Spark : What is the risk of referencing the whole object?

转载 作者:行者123 更新时间:2023-12-04 05:22:46 26 4
gpt4 key购买 nike

根据 Passing Functions to Spark ,它声称:
accessing fields of the outer object will reference the whole object; To avoid this issue ...
我正在考虑流动代码的风险是什么:

class MyClass {
val field = "Hello"
def doStuff(rdd: RDD[String]): RDD[String] = { rdd.map(x => field + x) }
}

引用所有这些 会不会有什么害处?

最佳答案

这将导致 Spark 序列化您的整个对象并将其发送给每个执行程序。如果对象的某些字段包含大量数据,则它可能会很慢。也可能导致 task not serializable如果您的对象不可序列化,则异常

这是一个有这个问题的人的例子:Task not serializable: java.io.NotSerializableException when calling function outside closure only on classes not objects

关于scala - 将函数传递给 Spark : What is the risk of referencing the whole object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28845172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com