QuestionQ111

VerifiedDeveloping Apache Spark™ DataFrame/DataSet API Applications

The code block below has an error. It is intended to create and register a SQL UDF named ASSESS_PERFORMANCE using the Python function assessPerformance() and apply it to column customerSatistfaction in table stores. Identify the error.

spark.udf.register("ASSESS_PERFORMANCE", assessPerformance)  
spark.sql("SELECT customerSatisfaction, assessPerformance(customerSatisfaction) AS result FROM stores")  
Explanation

spark.udf.register() registers the Python callable as a SQL function under the supplied name, and registered UDFs can be used in spark.sql() statements. The registered SQL identifier is ASSESS_PERFORMANCE; assessPerformance omits the underscore and therefore does not reference that registered function.

Learn more

Community Discussion

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