DataFrameWriter interface provides methods to save DataFrames to external storage systems, including local files, S3, and catalog tables.
Access
Access the writer through a DataFrame’swrite property:
Supported Storage Schemes
Amazon S3
Format:s3://{bucket_name}/{path_to_file}
- Uses boto3 to acquire AWS credentials
Local Files
Format:file://{absolute_or_relative_path} or implicit
- Paths without a scheme are treated as local files
Methods
save_as_table()
Saves the content of the DataFrame as a table in the catalog.Name of the table to save to.
Write mode:
error: Raises an error if table existsappend: Appends data to table if it existsoverwrite: Overwrites existing tableignore: Silently ignores operation if table exists
QueryMetrics - The query execution metrics
Examples
save_as_view()
Saves the content of the DataFrame as a view in the catalog.Name of the view to save to.
Optional human-readable view description to store in the catalog.
None
Example
csv()
Saves the content of the DataFrame as a single CSV file with comma as the delimiter and headers in the first row.Path to save the CSV file to. Must have a
.csv extension.Write mode:
error: Raises an error if file existsoverwrite: Overwrites the file if it existsignore: Silently ignores operation if file exists
QueryMetrics - The query execution metrics
Examples
parquet()
Saves the content of the DataFrame as a single Parquet file.Path to save the Parquet file to. Must have a
.parquet extension.Write mode:
error: Raises an error if file existsoverwrite: Overwrites the file if it existsignore: Silently ignores operation if file exists
QueryMetrics - The query execution metrics
Examples
Working with Query Metrics
All write methods (exceptsave_as_view) return a QueryMetrics object that provides information about the execution:
See Also
- DataFrameReader - Read data from files
- Catalog - Manage tables and views
- DataFrame - DataFrame operations
