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.
===========
Belen
1 month agoNell
2 months agoSunshine
2 months agoCasandra
2 months agoElenora
2 months agoJosue
2 months agoDomitila
2 months agoQueenie
3 months agoStevie
3 months agoTora
3 months agoBette
4 months agoLaurel
4 months agoEmiko
4 months agoBea
4 months agoShaniqua
4 months agoMiesha
4 months agoPok
5 months agoMollie
5 months agoTayna
5 months agoVerdell
5 months agoCarolynn
5 months agoCarmela
6 months agoShawana
6 months agoGaynell
6 months agoIola
6 months agoCornell
20 days agoHannah
26 days agoCarlee
1 month agoMarylyn
1 month agoLashawnda
5 months ago