Exam Certified Associate Developer for Apache Spark All QuestionsBrowse all questions from this exam
Question 133

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()))

    Correct Answer: E

    The error in the code block is that the cast() operation is a method in the Column class rather than a standalone function. Therefore, the correct usage would be to call cast() on the column itself, like storesDF.withColumn('storeId', col('storeId').cast(StringType())).

Discussion
JuanitoFMOption: E

https://spark.apache.org/docs/3.1.3/api/python/reference/api/pyspark.sql.Column.cast.html?highlight=cast

azure_bimonsterOption: E

E is the right

AnweeeOption: E

It is E, no doubt about it

gowthamsaraOption: E

E should be the answer