DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #22
The code block shown below should create and register a SQL UDF named "ASSESS_PERFORMANCE" using the Python function assessPerformance() and apply it to column customerSatisfaction in table stores…
The correct answer is A. 1. udf. To register a Python function as a named SQL UDF in PySpark, you use spark.udf.register(name, function, returnType). This makes the UDF accessible in SQL queries by the registered name. The correct fill-in is: 1=udf, 2=register, 3='ASSESS_PERFORMANCE' (the SQL-accessible name…
Question
The code block shown below should create and register a SQL UDF named "ASSESS_PERFORMANCE" using the Python function assessPerformance() and apply it to column customerSatisfaction in table stores. Choose the response that correctly fills in the numbered blanks within the code block to complete this task. Code block:
spark.1.2(3, 4) spark.sql("SELECT customerSatisfaction, 5(customerSatisfaction) AS result FROM stores")
Options
- A
- udf
- B
- udf
- C
- udf
- D
- register
- E
- udf
How the community answered
(25 responses)- A92% (23)
- C4% (1)
- D4% (1)
Explanation
To register a Python function as a named SQL UDF in PySpark, you use spark.udf.register(name, function, returnType). This makes the UDF accessible in SQL queries by the registered name. The correct fill-in is: 1=udf, 2=register, 3='ASSESS_PERFORMANCE' (the SQL-accessible name as a string), 4=assessPerformance (the Python function), 5=ASSESS_PERFORMANCE (used in the SQL SELECT). Option A correctly chains spark.udf.register(...) and references the UDF by its registered name in the SQL string.
Topics
Community Discussion
No community discussion yet for this question.