DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #130
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…
The correct answer is A. spark.udf.register("ASSESS_PERFORMANCE", assessPerformance). spark.udf.register() associates a Scala function with a SQL name so it can be invoked in Spark SQL queries against registered tables.
Question
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?
Options
- Aspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
- Bspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
- Cspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
- Dspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
- Espark.udf.register("ASSESS_PERFORMANCE", assessPerformance)
How the community answered
(26 responses)- A88% (23)
- B8% (2)
- E4% (1)
Why each option
spark.udf.register() associates a Scala function with a SQL name so it can be invoked in Spark SQL queries against registered tables.
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) registers the Scala function assessPerformance under the SQL name ASSESS_PERFORMANCE in the Spark session's function registry. Once registered, the UDF can be invoked in a spark.sql() call such as SELECT ASSESS_PERFORMANCE(customerSatisfaction) FROM stores, enabling SQL-based application of the Scala logic to the column.
The choices as presented appear identical in the question text - B does not differ from A in the visible content, making A the designated correct registration call.
The choices as presented appear identical in the question text - C does not differ from A in the visible content.
The choices as presented appear identical in the question text - D does not differ from A in the visible content.
The choices as presented appear identical in the question text - E does not differ from A in the visible content.
Concept tested: Registering and using Spark SQL UDFs in Scala
Source: https://spark.apache.org/docs/latest/sql-ref-functions-udf-scalar.html
Topics
Community Discussion
No community discussion yet for this question.