QuestionQ33

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below includes an error. It is intended to create a Python UDF, assessPerformanceUDF(), from the integer-returning Python function assessPerformance() and apply it to the customerSatisfaction column in DataFrame storesDF. Identify the error.

assessPerformanceUDF – udf(assessPerformance)  
storesDF.withColumn("result", assessPerformanceUDF(col("customerSatisfaction")))  
Explanation

A PySpark UDF created with udf() defaults to StringType when no return type is supplied. An integer-returning function requires an explicit integer return type, for example udf(assessPerformance, IntegerType()), so Spark uses the correct output schema.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!