Databricks Certified Associate Developer for Apache Spark — Question 213
The code block shown below should return a new DataFrame from DataFrame storesDF where column storeId is of the type string. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.
Code block:
storesDF.__1__("storeId", __2__("storeId").__3__(__4__)
Answer options
- A. 1. withColumn 2. col 3. cast 4. StringType()
- B. 1. withColumn 2. cast 3. col 4. StringType()
- C. 1. newColumn 2. col 3. cast 4. StringType()
- D. 1. withColumn 2. cast 3. col 4. StringType
- E. 1. withColumn 2. col 3. cast 4. StringType
Correct answer: A
Explanation
Option A is correct because it properly uses the withColumn method to create a new column with the specified transformations. The other options either misplace the function calls or do not utilize the correct order of operations, such as using 'cast' and 'col' incorrectly.