nerdexam
Databricks

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…

User-Defined Functions (UDFs)

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
    1. udf
  • B
    1. udf
  • C
    1. udf
  • D
    1. register
  • E
    1. udf

How the community answered

(25 responses)
  • A
    92% (23)
  • C
    4% (1)
  • D
    4% (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

#PySpark UDFs#Spark SQL#UDF Registration#User-Defined Functions

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Practice