【发布时间】:2020-12-03 01:03:43
【问题描述】:
我有一个用 scala 编写的数据框 a2:
val a3 = a2.select(printme.apply(col(“PlayerReference”)))
PlayerReference 列包含一个字符串。
调用 udf 函数:
val printme = udf({
st: String =>
val x = new JustPrint(st)
x.printMe();
})
这个 udf 函数调用一个 java 类:
public class JustPrint {
private String ss = null;
public JustPrint(String ss) {
this.ss = ss;
}
public void printMe() {
System.out.println("Value : " + this.ss);
}
}
但我对 udf 有此错误:
java.lang.UnsupportedOperationException: Schema for type Unit is not supported
本练习的目标是验证调用链。 我应该怎么做才能解决这个问题?
【问题讨论】:
-
您的 UDF 返回
Unit方法printMe()具有void返回类型,即Unit在 scala 中键入。在spark用户定义函数中应该返回non-Unit类型。如果要打印一些数据,或许使用Dataframeshow比较好。
标签: java scala user-defined-functions