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:
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:
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.
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()
But you also gave a type for the customerSatisfaction input parameter. I think the answer is A
I think it's B