Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Certified Associate Developer for Apache Spark topic 1 question 41 discussion

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")

  • A. 1. udf
    2. register
    3. "ASSESS_PERFORMANCE"
    4. assessPerformance
    5. ASSESS_PERFORMANCE
  • B. 1. udf
    2. register
    3. assessPerformance
    4. "ASSESS_PERFORMANCE"
    5. "ASSESS_PERFORMANCE"
  • C. 1. udf
    2. register
    3."ASSESS_PERFORMANCE"
    4. assessPerformance
    5. "ASSESS_PERFORMANCE"
  • D. 1. register
    2. udf
    3. "ASSESS_PERFORMANCE"
    4. assessPerformance
    5. "ASSESS_PERFORMANCE"
  • E. 1. udf
    2. register
    3. ASSESS_PERFORMANCE
    4. assessPerformance
    5. ASSESS_PERFORMANCE
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
jds0
1 month, 2 weeks ago
Selected Answer: A
Answer: A See code example below with Spark 3.5.1: from pyspark.sql import SparkSession spark = SparkSession.builder.appName("MyApp").getOrCreate() data = [ (0, 43161, "A"), (1, 51200, "A"), (3, 78367, "B"), ] storesDF = spark.createDataFrame(data, ["storeID", "sqft", "division"]) def assess_performance(x): return "Large" if x > 50000 else "Small" spark.udf.register("ASSESS_PERFORMANCE", assess_performance, "STRING") storesDF.createOrReplaceTempView("stores") df = spark.sql("SELECT StoreID, ASSESS_PERFORMANCE(sqft) AS performance FROM stores") df.show()
upvoted 1 times
...
azurearch
6 months ago
def assessperformance(): return 'Good' spark.udf.register("assessperformance",assessperformance) df = spark.sql("SELECT assessperformance()") df.show() A
upvoted 2 times
...
4be8126
1 year, 4 months ago
Selected Answer: A
Answer: A Explanation: udf: create a user-defined function (UDF) in PySpark register: register the UDF with Spark so it can be used in SQL queries "ASSESS_PERFORMANCE": name the UDF "ASSESS_PERFORMANCE" assessPerformance: specify the Python function to use for the UDF ASSESS_PERFORMANCE: use the registered UDF in the SQL query to apply the assessPerformance() function to the customerSatisfaction column.
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...