Databricks Certified Associate Developer for Apache Spark — Question 113
Which of the following code blocks writes DataFrame storesDF to file path filePath as parquet and partitions by values in column division?
Answer options
- A. storesDF.write.partitionBy(col("division")).path(filePath)
- B. storesDF.write.option("parquet").partitionBy("division").path(filePath)
- C. storesDF.write.option("parquet").partitionBy(col("division")).path(filePath)
- D. storesDF.write.partitionBy("division").parquet(filePath)
- E. storesDF.write().partitionBy("division").parquet(filePath)
Correct answer: D
Explanation
Option D is correct because it correctly uses the partitionBy method followed by the parquet method to save the DataFrame in the desired format and partitioning. Options A, B, C, and E are incorrect as they either misuse method chaining or do not follow the correct syntax for saving a DataFrame as parquet with partitioning.