DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #172
The code block shown below contains an error. The code block is intended to create and register a SQL UDF named "ASSESS_PERFORMANCE" using the Python function assessPerformance() and apply it to…
The correct answer is E. The wrong SQL function is used to compute column result - it should be. The error is that the SQL statement calls assessPerformance(customerSatisfaction) - the original Python function name - instead of the registered UDF name ASSESS_PERFORMANCE. When you register a UDF with spark.udf.register('ASSESS_PERFORMANCE', assessPerformance), Spark makes…
Question
The code block shown below contains an error. The code block is intended to create and register a SQL UDF named "ASSESS_PERFORMANCE" using the Python function assessPerformance() and apply it to column customerSatistfaction in table stores. Identify the error. Code block:
spark.udf.register("ASSESS_PERFORMANCE", assessPerformance) spark.sql("SELECT customerSatisfaction, assessPerformance(customerSatisfaction) AS result FROM stores")
Options
- AThere is no sql() operation - the DataFrame API must be used to apply the UDF
- BThe order of the arguments to spark.udf.register() should be reversed.
- CThe customerSatisfaction column cannot be called twice inside the SQL statement.
- DRegistered UDFs cannot be applied inside of a SQL statement.
- EThe wrong SQL function is used to compute column result - it should be
How the community answered
(26 responses)- A4% (1)
- C4% (1)
- E92% (24)
Explanation
The error is that the SQL statement calls assessPerformance(customerSatisfaction) - the original Python function name - instead of the registered UDF name ASSESS_PERFORMANCE. When you register a UDF with spark.udf.register('ASSESS_PERFORMANCE', assessPerformance), Spark makes it available in SQL under the registered name ASSESS_PERFORMANCE. The corrected SQL should read: SELECT customerSatisfaction, ASSESS_PERFORMANCE(customerSatisfaction) AS result FROM stores.
Topics
Community Discussion
No community discussion yet for this question.