This tutorial will explain how mode() function or mode parameter can be used to alter the behavior of write operation when data (directory) or table already exists.

PySpark: Dataframe Write Modes

This tutorial will explain how mode() function or mode parameter can be used to alter the behavior of write operation when data (directory) or table already exists.

Overwrite Existing Data: When overwrite mode is used then write operation will overwrite existing data (directory) or table with the content of dataframe. If data/table does not exists then write operation with overwrite mode will behave normally. Below examples are showing mode operation on CSV and JSON files only but this can be used with any file format / tables.
Append to Existing Data: When append mode is used then write operation will append the content of the dataframe to existing data directory or table. If data/table does not exists then write operation with append mode will behave normally. Below examples are showing mode operation on CSV and JSON files only but this can be used with any file format / tables.
Ignore Write Operation if data exists: When ignore mode is used then write operation will ignore current write operation if data / table already exists without throwing error or exception. If data/table does not exists then write operation with ignore mode will behave normally. Below examples are showing mode operation on CSV and JSON files only but this can be used with any file format / tables.
Throw Error in Write Operation: When error mode is used then write operation throws an exception if data or table already exists. If data/table does not exists then write operation with error mode will behave normally. Parameter values error, errorifexists and default are aliases of one another. Below examples are showing mode operation on CSV and JSON files only but this can be used with any file format / tables.