Skip to content

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).

await df.write.format("parquet").mode("overwrite").save("/path/to/output");
await df.write.mode("append").saveAsTable("analytics.events");

Spark source: DataFrameWriter.scala

new DataFrameWriter(df): DataFrameWriter;

Defined in: data-frame-writer.ts:39

ParameterType
dfDataFrame

DataFrameWriter

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).

ParameterType
numBucketsnumber
colstring
colsstring[]

this


csv(path): Promise<void>;

Defined in: data-frame-writer.ts:168

Shortcut for .format(“csv”).save(path).

ParameterType
pathstring

Promise<void>


format(fmt): this;

Defined in: data-frame-writer.ts:44

Set the output format (e.g. “parquet”, “json”, “csv”, “orc”, “delta”).

ParameterType
fmtstring

this


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.

ParameterType
tableNamestring

Promise<void>


json(path): Promise<void>;

Defined in: data-frame-writer.ts:163

Shortcut for .format(“json”).save(path).

ParameterType
pathstring

Promise<void>


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
ParameterType
mSaveMode

this


option(key, value): this;

Defined in: data-frame-writer.ts:62

Set a single write option.

ParameterType
keystring
valuestring

this


options(opts): this;

Defined in: data-frame-writer.ts:68

Set multiple write options.

ParameterType
optsRecord<string, string>

this


orc(path): Promise<void>;

Defined in: data-frame-writer.ts:178

Shortcut for .format(“orc”).save(path).

ParameterType
pathstring

Promise<void>


parquet(path): Promise<void>;

Defined in: data-frame-writer.ts:173

Shortcut for .format(“parquet”).save(path).

ParameterType
pathstring

Promise<void>


partitionBy(...columns): this;

Defined in: data-frame-writer.ts:74

Partition the output by the given column names.

ParameterType
columnsstring[]

this


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.

ParameterType
pathstring

Promise<void>


saveAsTable(tableName): Promise<void>;

Defined in: data-frame-writer.ts:131

Save the DataFrame as a named table.

ParameterTypeDescription
tableNamestringThe fully qualified or unqualified table name

Promise<void>


sortBy(...columns): this;

Defined in: data-frame-writer.ts:80

Sort the output within each partition by the given column names.

ParameterType
columnsstring[]

this


text(path): Promise<void>;

Defined in: data-frame-writer.ts:183

Shortcut for .format(“text”).save(path).

ParameterType
pathstring

Promise<void>