Databricks Certified Associate Developer for Apache Spark — Question 89

The code block shown below contains an error. The code block is intended to return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Identify the error.

Code block:

storesDF.withColumn(“storeId”, cast(col(“storeId”), StringType()))

Answer options

Correct answer: E

Explanation

The correct answer is E because the cast() operation is indeed a method associated with the Column class and cannot be used as a standalone function. The other options are incorrect because withColumn() can create new columns with the same name, DataFrame columns can be cast to new types, StringType requires parentheses, and col() requires the column name to be in quotes.