Exit DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK Databricks Certified Associate Developer for Apache Spark 3.0
Question 3 of 5
0% complete
Q3 Single choice

The code block displayed below contains an error. The code block should return a DataFrame in which column predErrorAdded contains the results of Python function add_2_if_geq_3 as applied to numeric and nullable column predError in DataFrame transactionsDf.

Find the error.

Code block:

1. def add_2_if_geq_3(x):

2. if x is None:

3. return x

4. elif x >= 3:

5. return x+2

6. return x

7.

8. add_2_if_geq_3_udf = udf(add_2_if_geq_3)

9.

10. transactionsDf.withColumnRenamed("predErrorAdded", add_2_if_geq_3_udf(col("predError")))

  • A

    The operator used to adding the column does not add column predErrorAdded to the DataFrame.

  • B

    Instead of col("predError"), the actual DataFrame with the column needs to be passed, like so transactionsDf.predError.

  • C

    The udf() method does not declare a return type.

  • D

    UDFs are only available through the SQL API, but not in the Python API as shown in the code block.

  • E

    The Python function is unable to handle null values, resulting in the code block crashing on execution.