DataFrameWriter
Defined in: data-frame-writer.ts:30
Writes the contents of a DataFrame to an external storage system or a catalog table.
Obtained via DataFrame.write. Mirrors Spark’s path-oriented
DataFrameWriter (V1). For catalog-aware, atomic table writes, use
DataFrameWriterV2 via df.writeTo(table).
Example
Section titled “Example”await df.write.format("parquet").mode("overwrite").save("/path/to/output");await df.write.mode("append").saveAsTable("analytics.events");Spark source: DataFrameWriter.scala
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DataFrameWriter(df): DataFrameWriter;Defined in: data-frame-writer.ts:39
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
df | DataFrame |
Returns
Section titled “Returns”DataFrameWriter
Methods
Section titled “Methods”bucketBy()
Section titled “bucketBy()”bucketBy( numBuckets, col, ... cols): this;Defined in: data-frame-writer.ts:89
Bucket the output by the given columns with a fixed number of buckets. Only applicable when saving to a table (saveAsTable).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
numBuckets | number |
col | string |
…cols | string[] |
Returns
Section titled “Returns”this
csv(path): Promise<void>;Defined in: data-frame-writer.ts:168
Shortcut for .format(“csv”).save(path).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
format()
Section titled “format()”format(fmt): this;Defined in: data-frame-writer.ts:44
Set the output format (e.g. “parquet”, “json”, “csv”, “orc”, “delta”).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
fmt | string |
Returns
Section titled “Returns”this
insertInto()
Section titled “insertInto()”insertInto(tableName): Promise<void>;Defined in: data-frame-writer.ts:146
Insert the DataFrame’s contents into the given table. Unlike saveAsTable, insertInto does not create the table; it must already exist.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
tableName | string |
Returns
Section titled “Returns”Promise<void>
json()
Section titled “json()”json(path): Promise<void>;Defined in: data-frame-writer.ts:163
Shortcut for .format(“json”).save(path).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
mode()
Section titled “mode()”mode(m): this;Defined in: data-frame-writer.ts:56
Set the save mode:
- “append” - Append to existing data
- “overwrite” - Overwrite existing data
- “error” (default) - Error if data already exists
- “ignore” - Silently ignore if data already exists
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
m | SaveMode |
Returns
Section titled “Returns”this
option()
Section titled “option()”option(key, value): this;Defined in: data-frame-writer.ts:62
Set a single write option.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
key | string |
value | string |
Returns
Section titled “Returns”this
options()
Section titled “options()”options(opts): this;Defined in: data-frame-writer.ts:68
Set multiple write options.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opts | Record<string, string> |
Returns
Section titled “Returns”this
orc(path): Promise<void>;Defined in: data-frame-writer.ts:178
Shortcut for .format(“orc”).save(path).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
parquet()
Section titled “parquet()”parquet(path): Promise<void>;Defined in: data-frame-writer.ts:173
Shortcut for .format(“parquet”).save(path).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
partitionBy()
Section titled “partitionBy()”partitionBy(...columns): this;Defined in: data-frame-writer.ts:74
Partition the output by the given column names.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…columns | string[] |
Returns
Section titled “Returns”this
save()
Section titled “save()”save(path): Promise<void>;Defined in: data-frame-writer.ts:118
Save the DataFrame to the given path.
Sends a WriteOperation command through the Spark Connect RPC.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>
saveAsTable()
Section titled “saveAsTable()”saveAsTable(tableName): Promise<void>;Defined in: data-frame-writer.ts:131
Save the DataFrame as a named table.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tableName | string | The fully qualified or unqualified table name |
Returns
Section titled “Returns”Promise<void>
sortBy()
Section titled “sortBy()”sortBy(...columns): this;Defined in: data-frame-writer.ts:80
Sort the output within each partition by the given column names.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…columns | string[] |
Returns
Section titled “Returns”this
text()
Section titled “text()”text(path): Promise<void>;Defined in: data-frame-writer.ts:183
Shortcut for .format(“text”).save(path).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
path | string |
Returns
Section titled “Returns”Promise<void>