trigger (DataStreamWriter)
Sets the trigger for the streaming query. If not set, the query runs as fast as possible, equivalent to processingTime='0 seconds'. Only one trigger parameter can be set at a time.
See Configure Structured Streaming trigger intervals.
Compute and pipeline execution
In Lakeflow pipelines, the pipeline manages stream execution. Use pipeline execution settings to control when pipeline data is processed.
When you use DataStreamWriter directly on serverless compute for notebooks and jobs, use availableNow=True. The default trigger, processingTime, continuous, and realTime are not supported on that compute. These restrictions do not apply to serverless pipeline execution modes. See Streaming limitations.
Syntax
trigger(*, processingTime=None, once=None, continuous=None, availableNow=None, realTime=None)
Parameters
Parameter | Type | Description |
|---|---|---|
| str, optional | A processing time interval string (for example, |
| bool, optional | If |
| str, optional | Not supported on Databricks. This parameter enables Apache Spark's experimental Continuous Processing mode, which differs from continuous pipeline mode. Use real-time mode for low-latency Structured Streaming queries. |
| bool, optional | If |
| str, optional | A batch duration string (for example, |
Returns
DataStreamWriter
Examples
df = spark.readStream.format("rate").load()
Trigger execution every 5 seconds:
df.writeStream.trigger(processingTime='5 seconds')
# <...streaming.readwriter.DataStreamWriter object ...>
Process all available data in multiple batches:
df.writeStream.trigger(availableNow=True)
# <...streaming.readwriter.DataStreamWriter object ...>
Configure real-time mode with five-minute batches. Records are processed as they arrive during each batch. Use a supported source, sink, and compute type:
kafka_df = (spark.readStream
.format("kafka")
.option("kafka.bootstrap.servers", "<bootstrap-servers>")
.option("subscribe", "<input-topic>")
.load())
kafka_df.writeStream.trigger(realTime="5 minutes")
# <...streaming.readwriter.DataStreamWriter object ...>