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:
A.
The input type of customerSatisfaction is not specified in the udf() operation.
B.
The return type of assessPerformanceUDF() must be specified.
C.
The withColumn() operation is not appropriate here - UDFs should be applied by iterating over rows instead.
D.
The assessPerformanceUDF() must first be defined as a Scala function and then converted to a UDF.
E.
UDFs can only be applied via SQL and not through the Data Frame API.
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()
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.
beds2898
3 months, 2 weeks agocarlosmps
5 months, 1 week agodeadbeef38
5 months agoSowwy1
7 months, 3 weeks ago