<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Trigger_(Structured_Streaming)</id>
	<title>Trigger (Structured Streaming) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Trigger_(Structured_Streaming)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Trigger_(Structured_Streaming)&amp;action=history"/>
	<updated>2026-12-06T00:07:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Trigger_(Structured_Streaming)&amp;diff=108&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@f2492a3</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Trigger_(Structured_Streaming)&amp;diff=108&amp;oldid=prev"/>
		<updated>2026-11-23T00:34:56Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@f2492a3&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Trigger&lt;br /&gt;
| also_known_as   = Streaming trigger, trigger policy&lt;br /&gt;
| field           = Stream processing&lt;br /&gt;
| key_parts       = Unspecified (default), processing time, once (deprecated), available now, continuous (experimental), real time&lt;br /&gt;
| implementations = [[Apache Spark]] [[Structured Streaming]]&lt;br /&gt;
| related         = [[Structured Streaming]], [[Watermark]], [[Exactly-once semantics]], [[Stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the v2.0.0, v2.2.0, v3.3.0, v3.4.0 and v4.0.0 to v4.3.0 tags of apache/spark (Trigger.java, Triggers.scala, python/pyspark/sql/streaming/readwriter.py, docs/streaming/apis-on-dataframes-and-datasets.md, docs/streaming/performance-tips.md, docs/streaming/real-time-mode.md), the Spark 3.4.0, 4.1.0, 4.2.0 and 4.3.0 release notes, SPARK-39805, SPARK-53737 and SPARK-57281}}&lt;br /&gt;
&lt;br /&gt;
In [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;trigger&amp;#039;&amp;#039;&amp;#039; is the setting on a streaming query that decides when the query processes data and which execution mode runs it: micro-batches as fast as possible, micro-batches on a fixed interval, all available data and then stop, or one of the low-latency modes.&amp;lt;ref name=&amp;quot;ssguide&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/streaming/apis-on-dataframes-and-datasets.md |title=Structured Streaming Programming Guide: APIs on DataFrames and Datasets (docs/streaming/apis-on-dataframes-and-datasets.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; The trigger is set with &amp;lt;code&amp;gt;DataStreamWriter.trigger()&amp;lt;/code&amp;gt;, and a query can have only one.&amp;lt;ref name=&amp;quot;pyrw&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/streaming/readwriter.py |title=python/pyspark/sql/streaming/readwriter.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Of the trigger types, &amp;#039;&amp;#039;&amp;#039;once&amp;#039;&amp;#039;&amp;#039; is deprecated since Spark 3.4.0 in favor of &amp;#039;&amp;#039;&amp;#039;available now&amp;#039;&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;&amp;#039;continuous&amp;#039;&amp;#039;&amp;#039; is still experimental; the &amp;#039;&amp;#039;&amp;#039;real-time&amp;#039;&amp;#039;&amp;#039; trigger was added in Spark 4.1.0.&amp;lt;ref name=&amp;quot;triggerjava&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java |title=sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;perf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/streaming/performance-tips.md |title=Structured Streaming Programming Guide: Performance Tips (docs/streaming/performance-tips.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;jira53737&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-53737 |title=SPARK-53737: Add Real-time Mode trigger |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Trigger types and status ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Trigger !! Scala/Java !! Python keyword !! Added !! Status in Spark 4.3.0 !! What it does&lt;br /&gt;
|-&lt;br /&gt;
| Unspecified (default)&lt;br /&gt;
| none&lt;br /&gt;
| none&lt;br /&gt;
| Spark 2.0.0&amp;lt;ref name=&amp;quot;pyrw&amp;quot; /&amp;gt;&lt;br /&gt;
| Active&lt;br /&gt;
| Starts each micro-batch as soon as the previous one finishes; the same as a processing-time trigger of 0 seconds&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;pyrw&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Processing time&lt;br /&gt;
| &amp;lt;code&amp;gt;Trigger.ProcessingTime(interval)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;processingTime&amp;lt;/code&amp;gt;&lt;br /&gt;
| Spark 2.2.0 for &amp;lt;code&amp;gt;Trigger.ProcessingTime&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
| Active&lt;br /&gt;
| Starts micro-batches at a fixed interval&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Once&lt;br /&gt;
| &amp;lt;code&amp;gt;Trigger.Once()&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;once&amp;lt;/code&amp;gt;&lt;br /&gt;
| Spark 2.2.0&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Deprecated&amp;#039;&amp;#039;&amp;#039; since Spark 3.4.0&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r340&amp;quot; /&amp;gt;&lt;br /&gt;
| Processes all available data in a single micro-batch, then stops&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Available now&lt;br /&gt;
| &amp;lt;code&amp;gt;Trigger.AvailableNow()&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;availableNow&amp;lt;/code&amp;gt;&lt;br /&gt;
| Spark 3.3.0&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
| Active; the replacement for once&lt;br /&gt;
| Processes all available data in one or more micro-batches, then stops&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Continuous&lt;br /&gt;
| &amp;lt;code&amp;gt;Trigger.Continuous(interval)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;continuous&amp;lt;/code&amp;gt;&lt;br /&gt;
| Spark 2.3.0&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Experimental&amp;#039;&amp;#039;&amp;#039;&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
| Runs the continuous processing engine with the given checkpoint interval; at-least-once&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Real time&lt;br /&gt;
| &amp;lt;code&amp;gt;Trigger.RealTime(duration)&amp;lt;/code&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;realTime&amp;lt;/code&amp;gt; (from Spark 4.2.0)&amp;lt;ref name=&amp;quot;r420&amp;quot; /&amp;gt;&lt;br /&gt;
| Spark 4.1.0&amp;lt;ref name=&amp;quot;jira53737&amp;quot; /&amp;gt;&lt;br /&gt;
| Active; see [[#Real-time trigger|Real-time trigger]]&lt;br /&gt;
| Runs Real-time Mode with long-running batches; the duration is mainly a checkpoint interval&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Processing-time and default triggers ==&lt;br /&gt;
With no trigger set, Structured Streaming runs in micro-batch mode and starts the next micro-batch as soon as the previous one completes.&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt; A processing-time trigger adds a fixed interval. If a micro-batch finishes early, the engine waits for the interval to end; if it runs past the interval, the next micro-batch starts as soon as it completes, without waiting for the next boundary. If no new data has arrived, no micro-batch starts.&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Triggers have been part of Structured Streaming since Spark 2.0.0.&amp;lt;ref name=&amp;quot;pyrw&amp;quot; /&amp;gt; Spark 2.2.0 added the &amp;lt;code&amp;gt;Trigger.ProcessingTime&amp;lt;/code&amp;gt; factory methods and deprecated the older &amp;lt;code&amp;gt;ProcessingTime&amp;lt;/code&amp;gt; class in their favor.&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v2.2.0/sql/core/src/main/scala/org/apache/spark/sql/streaming/ProcessingTime.scala |title=sql/core/src/main/scala/org/apache/spark/sql/streaming/ProcessingTime.scala (v2.2.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Once and available now ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Trigger.Once&amp;#039;&amp;#039;&amp;#039; runs one micro-batch over all available data and stops the query. The programming guide describes its use for clusters that start on a schedule, process what arrived since the last run and shut down.&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt; Trigger.Once is deprecated as of Spark 3.4.0 (SPARK-39805): the Java API carries &amp;lt;code&amp;gt;@Deprecated(since = &amp;quot;3.4.0&amp;quot;)&amp;lt;/code&amp;gt; and points to &amp;lt;code&amp;gt;AvailableNow()&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r340&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-4-0.html |title=Spark Release 3.4.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; It has not been removed; it is still in the Spark 4.3.0 API.&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Trigger.AvailableNow&amp;#039;&amp;#039;&amp;#039;, added in Spark 3.3.0, has the same goal but can split the work into several micro-batches according to source options such as &amp;lt;code&amp;gt;maxFilesPerTrigger&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;triggerjava&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt; The guide gives these reasons to prefer it over Once:&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
* All data available when the query starts is processed before it stops, including batches left uncommitted by an earlier run.&lt;br /&gt;
* The [[watermark]] advances after each batch, and a final no-data batch runs if the last batch moved the watermark, which keeps state small for stateful operators.&lt;br /&gt;
&lt;br /&gt;
If any source in the query does not support AvailableNow, Spark falls back to a single micro-batch, as with Once.&amp;lt;ref name=&amp;quot;ssguide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Continuous trigger ==&lt;br /&gt;
The continuous trigger runs &amp;#039;&amp;#039;&amp;#039;continuous processing&amp;#039;&amp;#039;&amp;#039;, an execution mode introduced in Spark 2.3 that the Spark 4.3.0 documentation still labels experimental. It aims at end-to-end latency near 1 millisecond with at-least-once guarantees, compared with about 100 milliseconds and exactly-once for the micro-batch engine.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt; The argument is a checkpoint interval, not a batch interval. Continuous processing supports only map-like operations (projections and selections), no aggregations, and a small set of sources and sinks such as Kafka and the rate source.&amp;lt;ref name=&amp;quot;perf&amp;quot; /&amp;gt; The Real-time Mode documentation describes continuous processing as legacy and recommends Real-time Mode for new low-latency workloads.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Real-time trigger ==&lt;br /&gt;
The real-time trigger enables &amp;#039;&amp;#039;&amp;#039;Real-time Mode&amp;#039;&amp;#039;&amp;#039;, added in Spark 4.1.0 (SPARK-53737, part of the SPARK-53736 SPIP) with support for stateless Scala queries.&amp;lt;ref name=&amp;quot;jira53737&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 4.2.0 added the &amp;lt;code&amp;gt;realTime&amp;lt;/code&amp;gt; keyword to PySpark (SPARK-54660).&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 4.3.0 added a first set of stateful queries: streaming deduplication, streaming aggregation and the JVM &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; operator.&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/docs/streaming/real-time-mode.md |title=Real-time Mode (docs/streaming/real-time-mode.md at v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Real-time Mode launches long-running tasks instead of one job per micro-batch, so records are processed and emitted as they arrive. The duration passed to the trigger (default 5 minutes) is mainly the checkpoint interval; it must be at least &amp;lt;code&amp;gt;spark.sql.streaming.realTimeMode.minBatchDuration&amp;lt;/code&amp;gt;, which defaults to 5 seconds. A real-time query must use the &amp;lt;code&amp;gt;update&amp;lt;/code&amp;gt; output mode. The Kafka source supports Real-time Mode, and supported sinks include Kafka, console and memory.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Spark 4.1.0 the internal &amp;lt;code&amp;gt;RealTimeTrigger&amp;lt;/code&amp;gt; class carried the &amp;lt;code&amp;gt;@Experimental&amp;lt;/code&amp;gt; annotation; the public &amp;lt;code&amp;gt;Trigger.RealTime&amp;lt;/code&amp;gt; methods did not.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.1.0/sql/api/src/main/scala/org/apache/spark/sql/execution/streaming/Triggers.scala |title=sql/api/src/main/scala/org/apache/spark/sql/execution/streaming/Triggers.scala (v4.1.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; SPARK-57281 removed the annotation. Its JIRA fix version is 4.3.0 and the Spark 4.3.0 release notes list it, although the change is also present at the v4.2.0 tag.&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-57281 |title=SPARK-57281: Remove @Experimental annotation from Real-time Mode trigger APIs |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
The following PySpark code, valid for Spark 4.3, runs a streaming query from JSON files into Parquet with the available-now trigger: it processes every file present at start, in one or more micro-batches, and then stops. Replacing &amp;lt;code&amp;gt;availableNow=True&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;processingTime=&amp;quot;1 minute&amp;quot;&amp;lt;/code&amp;gt; keeps the query running and starts a micro-batch every minute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
query = (spark.readStream.format(&amp;quot;json&amp;quot;).schema(&amp;quot;id LONG, msg STRING&amp;quot;)&lt;br /&gt;
         .option(&amp;quot;maxFilesPerTrigger&amp;quot;, 100)&lt;br /&gt;
         .load(&amp;quot;/data/in&amp;quot;)&lt;br /&gt;
         .writeStream.format(&amp;quot;parquet&amp;quot;)&lt;br /&gt;
         .option(&amp;quot;path&amp;quot;, &amp;quot;/data/out&amp;quot;)&lt;br /&gt;
         .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/data/chk&amp;quot;)&lt;br /&gt;
         .trigger(availableNow=True)&lt;br /&gt;
         .start())&lt;br /&gt;
query.awaitTermination()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Scala equivalent of the real-time trigger, for a supported query with a Kafka source and sink, is &amp;lt;code&amp;gt;.outputMode(&amp;quot;update&amp;quot;).trigger(Trigger.RealTime(&amp;quot;5 minutes&amp;quot;))&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Stream processing]]&lt;br /&gt;
* [[Spark Streaming (DStreams)]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>