从火花 UDF 返回火花列

时间:2021-03-12 18:01:43

标签: scala apache-spark user-defined-functions

我正在编写自己的自定义 UDF,它接受一个字节数组并将其作为 org.apache.spark.sql.Column 返回。

import org.apache.spark.sql.{Column, UDFRegistration}
import org.apache.spark.sql.functions.lit

private final def udf: (Array[Byte]) => Column = {
  
  case (bytes) => 
    // other logic
    lit(bytes)
}

override def register(registration: UDFRegistration): Unit = {
  registration.register("my_udf", udf)
}

但是这个错误会出现这个异常

Exception encountered when invoking run on a nested suite - Schema for type org.apache.spark.sql.Column is not supported *** ABORTED ***

我该怎么做?我四处寻找答案,但这似乎不可能。您可能会问“为什么不直接使用 lit”,但这里有一堆代码我省略了以简化事情

0 个答案:

没有答案