Skip to content

DataStreamWriter

Defined in: streaming/data-stream-writer.ts:30

Fluent writer for a streaming DataFrame, obtained via df.writeStream. Configure the output format, options, output mode, and trigger; terminate with start(path?) or toTable(name) to launch the query on the server.

foreach / foreachBatch are not yet supported because they require JS UDF execution, which isn’t shipped.

const query = await df.writeStream
.format("memory")
.queryName("inflight")
.outputMode("append")
.trigger(Trigger.processingTime("5 seconds"))
.start();
await query.processAllAvailable();
await query.stop();

Spark source: DataStreamWriter.scala

new DataStreamWriter(df): DataStreamWriter;

Defined in: streaming/data-stream-writer.ts:39

Parameter Type
df DataFrame

DataStreamWriter

format(source): this;

Defined in: streaming/data-stream-writer.ts:44

Set the sink format (e.g. "memory", "console", "parquet", "kafka").

Parameter Type
source string

this


option(key, value): this;

Defined in: streaming/data-stream-writer.ts:50

Set a single sink option. Booleans and numbers are stringified.

Parameter Type
key string
value string | number | boolean

this


options(opts): this;

Defined in: streaming/data-stream-writer.ts:56

Set multiple sink options at once. Non-string values are stringified.

Parameter Type
opts Record<string, string | number | boolean>

this


outputMode(mode): this;

Defined in: streaming/data-stream-writer.ts:66

How the streaming query writes results into the sink.

Not every sink supports every mode; see Spark’s docs for the matrix.

Parameter Type
mode StreamingOutputMode

this


partitionBy(...columns): this;

Defined in: streaming/data-stream-writer.ts:87

Partition the sink output by the given column names.

Parameter Type
columns string[]

this


queryName(name): this;

Defined in: streaming/data-stream-writer.ts:72

Name the query so it can be looked up via spark.streams.get(name).

Parameter Type
name string

this


start(path?): Promise<StreamingQuery>;

Defined in: streaming/data-stream-writer.ts:97

Start the streaming query against the given path (file sinks) or no path (for memory, console, kafka, etc.). Returns a handle for inspecting and controlling the running query.

Parameter Type
path? string

Promise<StreamingQuery>


toTable(tableName): Promise<StreamingQuery>;

Defined in: streaming/data-stream-writer.ts:110

Start the streaming query and write output to the named table. The table is created if it doesn’t exist (sink semantics depend on format).

Parameter Type
tableName string

Promise<StreamingQuery>


trigger(t): this;

Defined in: streaming/data-stream-writer.ts:81

Configure the trigger policy. See Trigger for the variants.

Parameter Type
t Trigger

this