【发布时间】:2017-11-19 15:15:41
【问题描述】:
我正在尝试使用udf,它相当于:
df.select(when(col("abc").isNotNull and col("abc") =!= "" and col("age") <= 18, 1).otherwise(0).alias("something"))
我将udf 声明为:
//return Int 0 or 1 if conditions are true
val myudf_x = udf((col_name: String, col_value: String, num: Int) => {
when(col_name.isNotNull and col_name =!= "" and col_value < num, 1).otherwise(0)
})
用法:
df.select(
"col_abc",
myudf(col("col_abc"), col("age"), 18).alias("something")
)
但我得到一个错误:
不支持 org.apache.spark.sql.Column 类型的架构
我也尝试过使用 String 类型而不是 column 类型的 udf
有什么问题?
谢谢
【问题讨论】:
标签: scala apache-spark apache-spark-sql user-defined-functions