【发布时间】:2022-01-12 05:43:03
【问题描述】:
Java 中以下 Scala 代码 sn-p 的准确翻译是什么?
import org.apache.spark.sql.functions.udf
def upper(s:String) : String = {
s.toUpperCase
}
val toUpper = udf(upper _)
peopleDS.select(peopleDS(“name”), toUpper(peopledS(“name”))).show
请用Java填写以下缺失的语句:
import org.apache.spark.sql.api.java.UDF1;
UDF1 toUpper = new UDF1<String, String>() {
public String call(final String str) throws Exception {
return str.toUpperCase();
}
};
peopleDS.select(peopleDS.col("name"), /* how to run toUpper("name")) ? */.show();
注意
注册 UDF,然后使用 selectExpr 调用对我有用,但我需要类似于上面显示的内容。
工作示例:
sqlContext.udf().register(
"toUpper",
(String s) -> s.toUpperCase(),
DataTypes.StringType
);
peopleDF.selectExpr("toUpper(name)","name").show();
【问题讨论】:
标签: java scala apache-spark