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

Certified Associate Developer for Apache Spark 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()))

Show Answer
Correct Answer: CE

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

4 comments
Sign in to comment
gowthamsaraOption: E
Jan 11, 2024

E should be the answer

AnweeeOption: E
Feb 4, 2024

It is E, no doubt about it

azure_bimonsterOption: E
Feb 9, 2024

E is the right

JuanitoFMOption: E
Feb 29, 2024

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