【发布时间】:2020-07-27 04:00:57
【问题描述】:
我正在使用以下 withcolumn 条件创建一个新的数据帧 df。我对其他数据帧也有以下 withcolumn 条件的相同用法。如何将这些所有 withcolumn 条件编写为通用函数并在所有数据帧中访问它。
val df = sampledf.withColumn("concat", concat($"columna", $"columnb", $"columnc"))
.withColumn("sub", $"columna" - $"columnb")
.withColumn("div", $"columna" / $"columnb")
.withColumn("mul", $"columna" * $"columnb")
【问题讨论】:
-
创建一个泛型函数也需要你传递所有的参数,所以为什么不使用 withColumn 本身呢。
标签: scala function apache-spark user-defined-functions