【发布时间】:2020-10-20 09:23:08
【问题描述】:
举个例子:
import org.apache.spark.sql.expressions.UserDefinedFunction
import org.apache.spark.sql.functions._
val testUdf: UserDefinedFunction = udf((a: String, b: String, c: Int) => {
val out = s"test1: $a $b $c"
println(out)
out
})
val testUdf2: UserDefinedFunction = udf((a: String, b: String, c: String) => {
val out = s"test2: $a $b $c"
println(out)
out
})
Seq(("hello", "world", null))
.toDF("a", "b", "c")
.withColumn("c", $"c" cast "Int")
.withColumn("test1", testUdf($"a", $"b", $"c"))
.withColumn("test2", testUdf2($"a", $"b", $"c"))
.show
testUdf 似乎没有被调用。没有错误,没有警告,它只是返回 null。
有没有办法检测这些静默故障?还有,这是怎么回事?
火花 2.4.4 斯卡拉 2.11
【问题讨论】:
标签: scala apache-spark apache-spark-sql user-defined-functions