2 of 55. Which command overwrites an existing JSON file when writing a DataFrame?
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.
===========
Queenie
9 hours agoStevie
6 days agoTora
11 days agoBette
16 days agoLaurel
21 days agoEmiko
26 days agoBea
1 month agoShaniqua
1 month agoMiesha
1 month agoPok
2 months agoMollie
2 months agoTayna
2 months agoVerdell
2 months agoCarolynn
2 months agoCarmela
3 months agoShawana
3 months agoGaynell
3 months agoIola
3 months agoLashawnda
2 months ago