New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Databricks Certified Associate Developer for Apache Spark 3.5 Exam - Topic 2 Question 3 Discussion

Actual exam question for Databricks's Databricks Certified Associate Developer for Apache Spark 3.5 exam
Question #: 3
Topic #: 2
[All Databricks Certified Associate Developer for Apache Spark 3.5 Questions]

2 of 55. Which command overwrites an existing JSON file when writing a DataFrame?

Show Suggested Answer Hide Answer
Suggested Answer: D

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.

===========


Contribute your Thoughts:

0/2000 characters
Queenie
9 hours ago
I thought it was C at first, but D makes more sense.
upvoted 0 times
...
Stevie
6 days ago
Definitely D! That's how you do it.
upvoted 0 times
...
Tora
11 days ago
I'm a bit confused; I thought "option" was the right way to set parameters, but I can't recall if it applies here.
upvoted 0 times
...
Bette
16 days ago
I feel like I've seen "option" used in other contexts, but for overwriting, I think it's definitely about the mode.
upvoted 0 times
...
Laurel
21 days ago
I remember practicing a similar question, and I think option D is correct because it specifies the mode as "overwrite."
upvoted 0 times
...
Emiko
26 days ago
I think the command to overwrite a JSON file is related to the mode, but I'm not entirely sure if it's "overwrite" or "append."
upvoted 0 times
...
Bea
1 month ago
D) df.write.mode("overwrite").json("path/to/file") is the way to go, unless you want to end up with a tangled web of JSON files.
upvoted 0 times
...
Shaniqua
1 month ago
Overwriting JSON files? Sounds like a recipe for a data disaster!
upvoted 0 times
...
Miesha
1 month ago
Hmm, I wonder if the file will be overwritten with my tax returns...
upvoted 0 times
...
Pok
2 months ago
D) df.write.mode("overwrite").json("path/to/file")
upvoted 0 times
...
Mollie
2 months ago
I'm pretty confident that D is the correct answer. The "overwrite" mode is specifically designed for overwriting existing files, so that's the way to go.
upvoted 0 times
...
Tayna
2 months ago
Okay, let me think this through. I know the "mode" option is used to specify whether to append or overwrite the data. So D seems like the right choice here.
upvoted 0 times
...
Verdell
2 months ago
It's D, right? Overwrite mode!
upvoted 0 times
...
Carolynn
2 months ago
C) df.write.option("overwrite").json("path/to/file")
upvoted 0 times
...
Carmela
3 months ago
I think it's D. Overwrite mode is clear.
upvoted 0 times
...
Shawana
3 months ago
I'm a little confused by all the different options here. I'll have to double-check the Spark documentation to make sure I'm choosing the right one.
upvoted 0 times
...
Gaynell
3 months ago
Hmm, I'm a bit unsure about this one. I know there are a few different ways to write a DataFrame to JSON, but I can't quite remember the exact syntax for overwriting an existing file.
upvoted 0 times
...
Iola
3 months ago
I think the answer is D. That looks like the most straightforward way to overwrite an existing JSON file.
upvoted 0 times
Lashawnda
2 months ago
I agree, D seems right.
upvoted 0 times
...
...

Save Cancel