scala - spark udf 没有被调用
问题描述
给定以下示例:
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 类型“Int”不允许空值。变量“c”类型可以更改为“Integer”。
推荐阅读
- flutter - Flutter:滑块自定义工具提示
- javascript - 随机加载内容
- python - 程序退出后,套接字描述符文件保留在磁盘上
- java - 如何在 Android Studio 中使用 TextView 创建指定的形状?
- node.js - Next Js中如何为每个用户分配子域
- html - 为什么在换行中编写 HTML 时元素之间有额外的空格
- javascript - CKEditor4-vue 工具导航不完整
- spring - Spring Beans:您可以将元素添加到注入列表中吗?
- c# - 如何在实体框架的 .Add() 中传递 DTO?
- python - 如何在 Jupyter Notebook 中仅打印单元格输出?