【发布时间】:2018-05-22 13:37:31
【问题描述】:
这是我的代码:
var exceptions: String = ""
val count = failures.fold("0")((x1, x2) => {
println(s"x1: $x1 and x2: $x2")
if (x1 != "-433" && x2 != "-433") {
(x1.toInt + x2.toInt).toString
} else {
println(s"before: $exceptions")
exceptions = exceptions + ", " + "There is an exception in processing, check the logs of executors for actual information"
println(s"after: $exceptions")
if (x1 == "-433") {
if (x2 != "-433") {
x2
} else "0"
}else {
if (x2 == "-433") {
x1
}else "0"
}
}
})
count 是一个 RDD[String]。最奇怪的是 execptions 以“”结尾。以下是日志:
x1:0 和 x2:-433
之前:
after: , 处理中出现异常,查看executors日志获取实际信息
x1:0 和 x2:0
最终:
【问题讨论】:
-
它是否与那些要求驱动程序变量未在并行化集合中更新的问题之一重复?请阅读有关 Spark 闭包的信息。你会得到一个更好的主意。
-
@RameshMaharjan:我不是在谈论抛出任何异常。
exceptions变量没有得到更新。但正如@philantrovert 指出的那样,由于驱动程序变量被传递给一组执行程序
标签: scala apache-spark fold