
Answer-first summary for fast verification
Answer: spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) spark.sql("SELECT customerSatisfaction, ASSESS_PERFORMANCE(customerSatisfaction) AS result FROM stores")
The correct answer is A because it properly registers the UDF 'ASSESS_PERFORMANCE' and then correctly applies it in a SQL query to the 'customerSatisfaction' column of the 'stores' table. Option B does not apply the UDF, Option C incorrectly uses the function name instead of the registered UDF name in the SQL query, Option D uses the function directly in the DataFrame API instead of the registered UDF, and Option E incorrectly tries to use the UDF name in the DataFrame API context where it is not valid.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
Which of the following code blocks correctly creates and registers a SQL UDF named "ASSESS_PERFORMANCE" using the Scala function assessPerformance() and applies it to the customerSatisfaction column in the stores table?
A
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) spark.sql("SELECT customerSatisfaction, ASSESS_PERFORMANCE(customerSatisfaction) AS result FROM stores")
B
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
C
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) spark.sql("SELECT customerSatisfaction, assessPerformance(customerSatisfaction) AS result FROM stores")
D
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) storesDF.withColumn("result", assessPerformance(col("customerSatisfaction")))
E
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) storesDF.withColumn("result", ASSESS_PERFORMANCE(col("customerSatisfaction")))