<?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=Output_mode</id>
	<title>Output mode - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Output_mode"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Output_mode&amp;action=history"/>
	<updated>2026-12-06T00:07:53Z</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=Output_mode&amp;diff=162&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Output_mode&amp;diff=162&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:46Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&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            = Output mode&lt;br /&gt;
| also_known_as   = Streaming output mode&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Append, update, complete; result table; [[watermark]]&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]] (&amp;lt;code&amp;gt;outputMode&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;writeStream&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Watermark]], [[Windowing (stream processing)]], [[foreachBatch]], [[Delta Lake]], [[Apache Iceberg]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (output modes, joins, unsupported operations, session windows) and Real-time Mode guide, the Delta Lake table streaming documentation and the Apache Iceberg 1.12.0 Spark Structured Streaming page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], the &amp;#039;&amp;#039;&amp;#039;output mode&amp;#039;&amp;#039;&amp;#039; of a streaming query says which rows of the query&amp;#039;s result table are written to the sink after each trigger: only new rows (&amp;#039;&amp;#039;&amp;#039;append&amp;#039;&amp;#039;&amp;#039;), only rows that changed (&amp;#039;&amp;#039;&amp;#039;update&amp;#039;&amp;#039;&amp;#039;) or the whole result (&amp;#039;&amp;#039;&amp;#039;complete&amp;#039;&amp;#039;&amp;#039;). The mode is set with &amp;lt;code&amp;gt;outputMode(...)&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;writeStream&amp;lt;/code&amp;gt;, and each kind of query supports only some modes.&amp;lt;ref name=&amp;quot;ss-out&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#output-modes |title=Structured Streaming: Output Modes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The output mode also decides how a [[watermark]] affects state and when windowed results appear.&lt;br /&gt;
&lt;br /&gt;
== What are the three output modes? ==&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Append&amp;#039;&amp;#039;&amp;#039; is the default. Only rows added to the result table since the last trigger are written, and a row is written once. It is allowed only for queries whose result rows never change afterwards, such as &amp;lt;code&amp;gt;select&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;where&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;flatMap&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt; and joins.&amp;lt;ref name=&amp;quot;ss-out&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Update&amp;#039;&amp;#039;&amp;#039; writes only the rows of the result table that changed since the last trigger. It has been available since Spark 2.1.1.&amp;lt;ref name=&amp;quot;ss-out&amp;quot; /&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Complete&amp;#039;&amp;#039;&amp;#039; writes the whole result table after every trigger. It is supported for aggregation queries.&amp;lt;ref name=&amp;quot;ss-out&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result table is a model, not a stored table: Spark keeps only the state it needs to produce the next output, and the sink decides how written rows are applied.&lt;br /&gt;
&lt;br /&gt;
== Which queries allow which output modes? ==&lt;br /&gt;
The table follows the compatibility matrix in the Spark 4.3.0 guide.&amp;lt;ref name=&amp;quot;ss-out&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Query type !! Append !! Update !! Complete !! Notes&lt;br /&gt;
|-&lt;br /&gt;
| Aggregation on event time with a watermark&lt;br /&gt;
| Yes || Yes || Yes&lt;br /&gt;
| Append emits each window once, after the watermark passes it, and drops its state. Update also drops old state. Complete keeps all state.&lt;br /&gt;
|-&lt;br /&gt;
| Other aggregations&lt;br /&gt;
| No || Yes || Yes&lt;br /&gt;
| Without a watermark, aggregates can change at any time, so append is not allowed and old state is never dropped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt;&lt;br /&gt;
| No || Yes || No&lt;br /&gt;
| Aggregations are not allowed in the same query.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt;&lt;br /&gt;
| In append operation mode || In update operation mode || No&lt;br /&gt;
| Aggregations are allowed after it only in append operation mode.&lt;br /&gt;
|-&lt;br /&gt;
| Joins&lt;br /&gt;
| Yes || No || No&lt;br /&gt;
| See [[Stream-stream join]].&lt;br /&gt;
|-&lt;br /&gt;
| Other queries&lt;br /&gt;
| Yes || Yes || No&lt;br /&gt;
| Complete would mean keeping all unaggregated data.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further restrictions apply to some operators. Streaming [[session window]] aggregations do not support update mode.&amp;lt;ref name=&amp;quot;ss-types&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#types-of-time-windows |title=Structured Streaming: Types of time windows (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Sorting a streaming DataFrame is supported only after an aggregation and in complete mode, and chaining several stateful operators is not supported in update or complete mode.&amp;lt;ref name=&amp;quot;ss-unsup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#unsupported-operations |title=Structured Streaming: Unsupported Operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Real-time Mode, added in Spark 4.1.0, requires update mode; a query with any other mode fails to start.&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does the output mode interact with watermarks? ==&lt;br /&gt;
For a windowed count with a 10-minute watermark, the three modes give different output streams for the same input:&amp;lt;ref name=&amp;quot;ss-out&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ss-late&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#conditions-for-watermarking-to-clean-aggregation-state |title=Structured Streaming: Conditions for watermarking to clean aggregation state (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* In append mode, the window 12:00 to 12:10 is written once, with its final count, after the watermark passes 12:10. Its output is therefore delayed by the watermark threshold.&lt;br /&gt;
* In update mode, the window&amp;#039;s running count is written after every trigger in which it changes, until the watermark passes it.&lt;br /&gt;
* In complete mode, every window ever seen is written after every trigger, and no state is dropped.&lt;br /&gt;
&lt;br /&gt;
For the watermark to clean aggregation state, the output mode must be append or update, the aggregation must group by the event-time column or a window on it, and &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt; must be called on that column before the aggregation.&amp;lt;ref name=&amp;quot;ss-late&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which output modes do table formats support as sinks? ==&lt;br /&gt;
The [[Delta Lake]] streaming sink supports append mode, which adds new records to the table, and complete mode, which replaces the table with each batch&amp;#039;s result.&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/delta-streaming.html |title=Table streaming reads and writes |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; To apply update-mode output to a Delta table as row-level upserts, the Delta documentation uses [[foreachBatch]] with &amp;lt;code&amp;gt;MERGE&amp;lt;/code&amp;gt;, and describes update mode as much more efficient than complete mode for streaming aggregates.&amp;lt;ref name=&amp;quot;delta-merge&amp;quot;&amp;gt;{{Cite web |url=https://docs.delta.io/latest/delta-update.html#upsert-from-streaming-queries-using-foreachbatch |title=Table deletes, updates, and merges: Upsert from streaming queries using foreachBatch |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The [[Apache Iceberg]] Spark sink also supports append mode (append each micro-batch&amp;#039;s rows) and complete mode (replace the table contents every micro-batch).&amp;lt;ref name=&amp;quot;iceberg&amp;quot;&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-structured-streaming/ |title=Spark Structured Streaming (Apache Iceberg 1.12.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import functions as F&lt;br /&gt;
&lt;br /&gt;
counts = (spark.readStream.table(&amp;quot;main.web.page_views&amp;quot;)&lt;br /&gt;
    .withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;)&lt;br /&gt;
    .groupBy(F.window(&amp;quot;ts&amp;quot;, &amp;quot;5 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
    .count())&lt;br /&gt;
&lt;br /&gt;
# Final counts only, one row per window, appended to a Delta table&lt;br /&gt;
(counts.writeStream&lt;br /&gt;
    .outputMode(&amp;quot;append&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/checkpoints/page_counts&amp;quot;)&lt;br /&gt;
    .toTable(&amp;quot;main.web.page_counts&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Windowing (stream processing)]]&lt;br /&gt;
* [[foreachBatch]]&lt;br /&gt;
* [[Trigger (Structured Streaming)]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>