public class DataFrameWriter extends Object
DataFrame.write method.
mode() method.
This method returns a DataFrameWriter that is configured to save data using the specified
mode. The default SaveMode is SaveMode.Append.
options or option method.
saveAsTable method to save the data to the specified destination.
DataFrame.write method.
DataFrame.mode method. This method returns a DataFrameWriter that is configured to save
data using the specified mode. The default SaveMode is SaveMode.ErrorIfExists for this case.
options or option method.
csv method.
json method.
parquet method.
| Modifier and Type | Method and Description |
|---|---|
DataFrameWriterAsyncActor |
async()
Returns a DataFrameWriterAsyncActor object that can be used to execute DataFrameWriter actions
asynchronously.
|
WriteFileResult |
csv(String path)
Saves the contents of the DataFrame to a CSV file on a stage.
|
WriteFileResult |
json(String path)
Saves the contents of the DataFrame to a JSON file on a stage.
|
DataFrameWriter |
mode(SaveMode saveMode)
Returns a new DataFrameWriter with the specified save mode configuration.
|
DataFrameWriter |
mode(String saveMode)
Returns a new DataFrameWriter with the specified save mode configuration.
|
DataFrameWriter |
option(String key,
Object value)
Sets the specified option in the DataFrameWriter.
|
DataFrameWriter |
options(Map<String,Object> configs)
Sets multiple specified options in the DataFrameWriter.
|
WriteFileResult |
parquet(String path)
Saves the contents of the DataFrame to a Parquet file on a stage.
|
void |
saveAsTable(String tableName)
Writes the data to the specified table in a Snowflake database.
|
void |
saveAsTable(String[] multipartIdentifier)
Writes the data to the specified table in a Snowflake database.
|
public DataFrameWriter option(String key, Object value)
Use this method to configure options:
Use this method to configure options:
Note that you cannot use the options or option methods to set the following
options:
mode method instead.
SaveMode.Overwrite.
SaveMode.ErrorIfExists.
For example:
df.write().option("compression", "none").csv("@myStage/prefix");
key - Name of the option.value - Value of the option.DataFrameWriterpublic DataFrameWriter options(Map<String,Object> configs)
Use this method to configure options:
Use this method to configure options:
Note that you cannot use the options or option methods to set the following
options:
mode method instead.
SaveMode.Overwrite.
SaveMode.ErrorIfExists.
For example:
Map<String, Object> configs = new HashMap<>();
configs.put("compression", "none");
df.write().options(configs).csv("@myStage/prefix");
configs - Map of the names of options (e.g. compression, etc.) and their
corresponding values.DataFrameWriterpublic WriteFileResult csv(String path)
For example:
df.write().option("compression", "none").csv("@myStage/prefix");
path - The path (including the stage name) to the CSV file.WriteFileResultpublic WriteFileResult json(String path)
NOTE: You can call this method only on a DataFrame that contains a column of the type
Variant, Array, or Map. If the DataFrame does not contain a column of one of these types, you
must call the to_variant, array_construct, or object_construct to
return a DataFrame that contains a column of one of these types.
For example:
df.write().option("compression", "none").json("@myStage/prefix");
path - The path (including the stage name) to the JSON file.WriteFileResultpublic WriteFileResult parquet(String path)
For example:
df.write().option("compression", "lzo").parquet("@myStage/prefix");
path - The path (including the stage name) to the Parquet file.WriteFileResultpublic void saveAsTable(String tableName)
tableName can be a
fully-qualified object identifier.
For example:
df.write().saveAsTable("db1.public_schema.table1");
tableName - Name of the table where the data should be saved.public void saveAsTable(String[] multipartIdentifier)
For example:
df.write().saveAsTable(new String[]{"db_name", "schema_name", "table_name"})
multipartIdentifier - A sequence of strings that specify the database name, schema name,
and table name.public DataFrameWriter mode(String saveMode)
saveMode - One of the following strings: `"APPEND"`, `"OVERWRITE"`, `"ERRORIFEXISTS"`, or
`"IGNORE"`public DataFrameWriter mode(SaveMode saveMode)
saveMode - One of the following save modes: SaveMode.Append, SaveMode.Overwrite, SaveMode.ErrorIfExists, SaveMode.Ignorepublic DataFrameWriterAsyncActor async()
© 2023 Snowflake Inc. All Rights Reserved