Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this 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:

    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
carlosmpsOption: B

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

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

Sowwy1Option: B

I think it's B