【发布时间】:2018-04-23 02:03:07
【问题描述】:
我正在尝试制作这样的 UDF:
import org.apache.spark.sql.functions.udf
def myFunction = udf( (input: String, modifier: Seq[String]) => {
// Logic goes here...
return Option(myString)
})
该函数在逻辑中有几个退出点,但它抱怨返回语句如下:
Message: <console>:69: error: method myFunction has return statement; needs result type
return Option(myString)
过去几个小时我一直在试图弄清楚如何将返回类型声明为 Option[String],但似乎没有任何效果。
我认为这是正确的,但它不喜欢它:
udf( (input: String, modifier: Seq[String]) => Option[String] {
【问题讨论】:
-
我觉得答案就在这个地方:stackoverflow.com/questions/2088524/… 但我还没有找到任何可行的方法。
-
你不需要 udf 函数中的返回词,并且来自 udf 函数的返回对象的数据类型应该是我在stackoverflow.com/a/49641733/5880706中解释的类型之一
-
你能添加你的UDF定义吗?
Option(myString)看起来不错
标签: scala apache-spark user-defined-functions