nerdexam
Databricks

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.

Implementing User-Defined Functions (UDFs) in Spark SQL

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)
  • A
    88% (23)
  • B
    8% (2)
  • E
    4% (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.

Aspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)Correct

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.

Bspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)

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.

Cspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)

The choices as presented appear identical in the question text - C does not differ from A in the visible content.

Dspark.udf.register("ASSESS_PERFORMANCE", assessPerformance)

The choices as presented appear identical in the question text - D does not differ from A in the visible content.

Espark.udf.register("ASSESS_PERFORMANCE", assessPerformance)

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

#UDFs#Spark SQL#Scala UDFs#Function Registration

Community Discussion

No community discussion yet for this question.

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