Databricks Certified Associate Developer for Apache Spark — Question 154
Which of the following code blocks writes DataFrame storesDF to file path filePath as text files overwriting any existing files in that location?
Answer options
- A. storesDF.write(filePath, mode = "overwrite", source = "text")
- B. storesDF.write.mode("overwrite").text(filePath)
- C. storesDF.write.mode("overwrite").path(filePath)
- D. storesDF.write.option("text", "overwrite").path(filePath)
- E. storesDF.write().mode("overwrite").text(filePath)
Correct answer: B
Explanation
Option B is correct because it correctly uses the method chaining to set the mode to 'overwrite' and then specifies the file path to save as text. Options A and E have incorrect method placements or syntax for writing to a file. Option C incorrectly uses 'path' instead of 'text', and Option D misuses the 'option' method, which is not applicable in this context.