Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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 |
# +---+-------------+