Certified Associate Developer for Apache Spark Exam QuestionsBrowse all questions from this exam

Certified Associate Developer for Apache Spark Exam - Question 105


The code block shown below contains an error. The code block is intended to create the Scala UDF assessPerformanceUDF() and apply it to the integer column customers1t1sfaction in Data Frame storesDF. Identify the error.

Code block:

Show Answer
Correct Answer: A

The code provided in the image uses a UDF (user-defined function) but does not specify the input type of the parameter 'customerSatisfaction'. In Scala, when creating UDFs, the input types must be explicitly specified for the UDF to work correctly. This omission is the likely source of the error in the code block.

Discussion

2 comments
Sign in to comment
Sowwy1Option: B
Apr 2, 2024

I think it's B

carlosmpsOption: B
Jun 21, 2024

Ans. B val assessPerformanceUDF = udf((customerSatisfaction: Int) => { customerSatisfaction match { case x if x < 20 => 1 case x if x > 80 => 3 case _ => 2 } }, IntegerType) // Apply the UDF to the DataFrame val resultDF = storesDF.withColumn("result", assessPerformanceUDF(col("customerSatisfaction"))) resultDF.show()

deadbeef38
Jun 22, 2024

But you also gave a type for the customerSatisfaction input parameter. I think the answer is A