繁体   English   中英

Spark - Hive UDF 正在使用 Spark-SQL,但不适用于 DataFrame

[英]Spark - Hive UDF is working with Spark-SQL but not with DataFrame

如果我在火花 SQL 中使用 hive UDF,它就可以工作。 如下所述。

val df=List(("$100", "$90", "$10")).toDF("selling_price", "market_price", "profit")
df.registerTempTable("test")
spark.sql("select default.encrypt(selling_price,'sales','','employee','id') from test").show

但是以下不起作用。

//following is not working. not sure if you need to register a function for this 
val encDF = df.withColumn("encrypted", default.encrypt($"selling_price","sales","","employee","id"))
encDF.show

错误

 error: not found: value default

Hive UDF 仅在通过 Spark SQL 访问时可用。 它在 Scala 环境中不可用,因为它没有在那里定义。 但是您仍然可以使用expr访问 Hive UDF:

df.withColumn("encrypted", expr("default.encrypt(selling_price,'sales','','employee','id')"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM