问题:
1)如果输入是包含null以下内容的原始类型的列,Spark不会调用UDF :
inputDF.show()
+-----+
| x |
+-----+
| null|
| 1.0|
+-----+
inputDF
.withColumn("y",
udf { (x: Double) => 2.0 }.apply($"x") // will not be invoked if $"x" == null
)
.show()
+-----+-----+
| x | y |
+-----+-----+
| null| null|
| 1.0| 2.0|
+-----+-----+
Run Code Online (Sandbox Code Playgroud)
2)无法null从UDF 生成原始类型的列:
udf { (x: String) => null: Double } // compile error