Note
Kailangan ng pahintulot para ma-access ang page na ito. Maaari mong subukang mag-sign in o magpalit ng mga direktoryo.
Ang pag-access sa pahinang ito ay nangangailangan ng pahintulot. Maaari mong subukang baguhin ang mga direktoryo.
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 |
# +---+-------------+