DATABRICKS-CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK · Question #85
Which of the following code blocks writes DataFrame storesDF to file path filePath as parquet overwriting any existing files in that location?
The correct answer is C. storesDF.write.mode("overwrite").parquet(filePath). In PySpark, DataFrame.write is a property (not a method), returning a DataFrameWriter object - you chain .mode("overwrite") to set the save mode, then .parquet(filePath) to both specify the format and trigger the actual write. Option C follows this exact pattern correctly. Why…
Question
Which of the following code blocks writes DataFrame storesDF to file path filePath as parquet overwriting any existing files in that location?
Options
- AstoresDF.write(filePath, mode = "overwrite")
- BstoresDF.write().mode("overwrite").parquet(filePath)
- CstoresDF.write.mode("overwrite").parquet(filePath)
- DstoresDF.write.option("parquet", "overwrite").path(filePath)
- EstoresDF.write.mode("overwrite").path(filePath)
How the community answered
(46 responses)- A2% (1)
- B4% (2)
- C91% (42)
- D2% (1)
Explanation
In PySpark, DataFrame.write is a property (not a method), returning a DataFrameWriter object - you chain .mode("overwrite") to set the save mode, then .parquet(filePath) to both specify the format and trigger the actual write. Option C follows this exact pattern correctly.
Why the distractors fail:
- A -
writeis a property, not callable;write(filePath, ...)raises aTypeError. - B - Same problem:
write()with parentheses is invalid syntax in the PySpark API. - D -
.option()is for format-specific key/value settings (e.g., delimiter), not for specifying write mode or format;.path()is not a validDataFrameWritertrigger method. - E -
.path()does not exist onDataFrameWriteras a write-triggering method; the format method (.parquet(),.csv(), etc.) is what specifies format and initiates the write.
Memory tip: Use the chain write → mode → format(path): the format method (.parquet(), .csv(), .json()) always comes last because it both declares the format and pulls the trigger on the write operation.
Topics
Community Discussion
No community discussion yet for this question.