簡體   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