Exam Associate-Developer-Apache-Spark-3.5 Topic 1 Question 71 Discussion
Actual exam question for Databricks's Associate-Developer-Apache-Spark-3.5 exam
Question #: 71
Topic #: 1
Question #: 71
Topic #: 1
2 of 55. Which command overwrites an existing JSON file when writing a DataFrame?
Suggested Answer: D Vote an answer
When writing DataFrames to files using the Spark DataFrameWriter API, Spark by default raises an error if the target path already exists. To explicitly overwrite existing data, you must specify the write mode as "overwrite".
Correct Syntax:
df.write.mode("overwrite").json("path/to/file")
This command removes the existing file or directory at the specified path and writes the new output in JSON format.
Other supported save modes include:
"append" - Adds new data to existing files.
"ignore" - Skips writing if the path already exists.
"error" or "errorifexists" - Fails the job if the output path exists (default).
Why other options are incorrect:
A: Defaults to "error" mode, which fails if the path exists.
B: "append" only adds data; it does not overwrite existing data.
C: .option("overwrite") is invalid - mode("overwrite") must be used instead.
Reference (Databricks Apache Spark 3.5 - Python / Study Guide):
PySpark API Reference: DataFrameWriter.mode() - describes valid write modes including "overwrite".
PySpark API Reference: DataFrameWriter.json() - method to write DataFrames in JSON format.
Databricks Certified Associate Developer for Apache Spark Exam Guide (June 2025): Section "Using Spark DataFrame APIs" - Reading and writing DataFrames using save modes, schema management, and partitioning.
Correct Syntax:
df.write.mode("overwrite").json("path/to/file")
This command removes the existing file or directory at the specified path and writes the new output in JSON format.
Other supported save modes include:
"append" - Adds new data to existing files.
"ignore" - Skips writing if the path already exists.
"error" or "errorifexists" - Fails the job if the output path exists (default).
Why other options are incorrect:
A: Defaults to "error" mode, which fails if the path exists.
B: "append" only adds data; it does not overwrite existing data.
C: .option("overwrite") is invalid - mode("overwrite") must be used instead.
Reference (Databricks Apache Spark 3.5 - Python / Study Guide):
PySpark API Reference: DataFrameWriter.mode() - describes valid write modes including "overwrite".
PySpark API Reference: DataFrameWriter.json() - method to write DataFrames in JSON format.
Databricks Certified Associate Developer for Apache Spark Exam Guide (June 2025): Section "Using Spark DataFrame APIs" - Reading and writing DataFrames using save modes, schema management, and partitioning.
by Levi at Sep 28, 2026, 10:08 AM
0
0
0
10
Comments
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Report Comment
Commenting
You can sign-up / login (it's free).