我使用Spark 2.2和Scala 2.11。我有这段代码,我在行df.show()
处收到任务序列化错误。但是,当我将df.show()
替换为df.count()
时,它运行良好并显示DataFrame中的行数:
def detection(z: Double, p: Double): String = {
var value : String = "-"
if (z < 1) {
if (p < 1) value = "A"
else value = "B"
}
else {
if (p < 1) value = "C"
else value = "D"
}
value
}
val detectionUdf = udf(detection _)
df = df.withColumn("det",detectionUdf(df("col1"), df("col2")))
df.show()