Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Specifies the behavior when data or table already exists.
Syntax
mode(saveMode)
Parameters
| Parameter | Type | Description |
|---|---|---|
saveMode |
str | The save mode. Accepted values are 'append' (append to existing data), 'overwrite' (overwrite existing data), 'error' or 'errorifexists' (throw an exception if data exists), and 'ignore' (silently skip if data exists). |
Returns
DataFrameWriter
Examples
Write a Parquet file back with various modes, and read it back.
import tempfile
with tempfile.TemporaryDirectory(prefix="mode") as d:
# Overwrite the path with a new Parquet file
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").format("parquet").save(d)
# Append another DataFrame into the Parquet file
spark.createDataFrame(
[{"age": 120, "name": "Sue"}]
).write.mode("append").format("parquet").save(d)
# Read the Parquet file as a DataFrame.
spark.read.parquet(d).show()
# +---+-------------+
# |age| name|
# +---+-------------+
# |120| Sue |
# |100| Alice |
# +---+-------------+