Databricks Certified Associate Developer for Apache Spark — Question 129
Which of the following code blocks creates and registers a SQL UDF named "ASSESS_PERFORMANCE" using the Scala function assessPerformance() and applies it to column customerSatisfaction in table stores?
Answer options
- 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")))
Correct answer: A
Explanation
Option A is correct because it properly registers the UDF 'ASSESS_PERFORMANCE' and uses it in a SQL query to select customer satisfaction along with the result of the UDF. The other options either fail to execute the SQL query that applies the UDF to the column or use incorrect syntax that does not meet the requirement of the question.