<?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=Windowing_(stream_processing)</id>
	<title>Windowing (stream processing) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Windowing_(stream_processing)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Windowing_(stream_processing)&amp;action=history"/>
	<updated>2026-12-06T00:13:25Z</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=Windowing_(stream_processing)&amp;diff=217&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=Windowing_(stream_processing)&amp;diff=217&amp;oldid=prev"/>
		<updated>2026-11-25T00:53:03Z</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            = Windowing (stream processing)&lt;br /&gt;
| also_known_as   = Time windows, windowed aggregation&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Window type (tumbling, sliding or hopping, session), window size, slide, gap, time column, [[watermark]]&lt;br /&gt;
| implementations = [[Structured Streaming]] (&amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt;), [[Apache Flink]] (window assigners, windowing TVFs), Kafka Streams (&amp;lt;code&amp;gt;TimeWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SlidingWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;SessionWindows&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Session window]], [[Event time and processing time]], [[Watermark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide and &amp;lt;code&amp;gt;python/pyspark/sql/functions/builtin.py&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the Apache Flink 2.3 DataStream &amp;quot;Windows&amp;quot; and SQL &amp;quot;Windowing TVF&amp;quot; pages, and the Kafka Streams 4.4 DSL developer guide}}&lt;br /&gt;
&lt;br /&gt;
In [[stream processing]], &amp;#039;&amp;#039;&amp;#039;windowing&amp;#039;&amp;#039;&amp;#039; is dividing an unbounded stream into finite groups of records, usually by time, so that aggregations such as counts and averages can be computed and emitted for each group. The three common window types are &amp;#039;&amp;#039;&amp;#039;tumbling&amp;#039;&amp;#039;&amp;#039; (fixed size, no overlap), &amp;#039;&amp;#039;&amp;#039;sliding&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;hopping&amp;#039;&amp;#039;&amp;#039; (fixed size, overlapping) and &amp;#039;&amp;#039;&amp;#039;session&amp;#039;&amp;#039;&amp;#039; windows (variable size, closed by a gap of inactivity). In [[Apache Spark]] [[Structured Streaming]], a window is a grouping key built with the &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; function over an [[Event time and processing time|event-time]] column, and a [[watermark]] decides when a window is complete.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#window-operations-on-event-time |title=Structured Streaming: Window Operations on Event Time (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What window types exist? ==&lt;br /&gt;
Structured Streaming supports three types of time windows: tumbling, sliding and session.&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;&lt;br /&gt;
&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;tumbling window&amp;#039;&amp;#039;&amp;#039; is one of a series of fixed-size, non-overlapping, contiguous time intervals. Each record belongs to exactly one window.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;sliding window&amp;#039;&amp;#039;&amp;#039; also has a fixed size, but a new window starts every &amp;#039;&amp;#039;slide&amp;#039;&amp;#039; interval. When the slide is shorter than the size, windows overlap and one record belongs to several windows.&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
* A &amp;#039;&amp;#039;&amp;#039;session window&amp;#039;&amp;#039;&amp;#039; has no fixed size. It starts with a record and grows while further records arrive within a gap duration; it closes when no record arrives within the gap. See [[Session window]].&amp;lt;ref name=&amp;quot;ss-types&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark&amp;#039;s guide uses the example of counting words in 10-minute windows that slide every 5 minutes: a word received at 12:07 is counted in both the 12:00 to 12:10 window and the 12:05 to 12:15 window.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does windowing work in Structured Streaming? ==&lt;br /&gt;
The &amp;lt;code&amp;gt;window(timeColumn, windowDuration, slideDuration=None, startTime=None)&amp;lt;/code&amp;gt; function, available since Spark 2.0.0, assigns each row to one or more windows. Without &amp;lt;code&amp;gt;slideDuration&amp;lt;/code&amp;gt;, the windows are tumbling; the slide must be less than or equal to the window size.&amp;lt;ref name=&amp;quot;builtin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/functions/builtin.py |title=python/pyspark/sql/functions/builtin.py (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Window starts are inclusive and ends are exclusive, so 12:05 falls in &amp;lt;code&amp;gt;[12:05, 12:10)&amp;lt;/code&amp;gt; and not in &amp;lt;code&amp;gt;[12:00, 12:05)&amp;lt;/code&amp;gt;. Windows are aligned to 1970-01-01 00:00:00 UTC; &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt; shifts them, for example to hourly windows that start 15 minutes past the hour. Durations are fixed lengths of time, not calendar units, and windows measured in months are not supported. The result is a struct column named &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;start&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt; fields.&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because a window is just a grouping key, a windowed aggregation is written as &amp;lt;code&amp;gt;groupBy(window(...), ...)&amp;lt;/code&amp;gt;, and the same query runs on a batch DataFrame and on a stream.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; function, added in Spark 3.4.0, returns a timestamp for a window column, which lets one windowed aggregation feed another, for example 5-minute windows rolled up into 1-hour windows.&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
On a stream, a windowed aggregation keeps state for every open window. A watermark on the same event-time column lets Spark drop the state of windows that the watermark has passed; in append [[output mode]], each window is emitted once, after that point.&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#handling-late-data-and-watermarking |title=Structured Streaming: Handling Late Data and Watermarking (Spark 4.3.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;
events = spark.readStream.table(&amp;quot;main.web.page_views&amp;quot;)   # columns: ts, page&lt;br /&gt;
&lt;br /&gt;
tumbling = (events.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;
sliding = (events.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;10 minutes&amp;quot;, &amp;quot;5 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
           .count())&lt;br /&gt;
&lt;br /&gt;
sessions = (events.withWatermark(&amp;quot;ts&amp;quot;, &amp;quot;10 minutes&amp;quot;)&lt;br /&gt;
            .groupBy(F.session_window(&amp;quot;ts&amp;quot;, &amp;quot;30 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
            .count())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The same queries in Spark SQL use &amp;lt;code&amp;gt;window(ts, &amp;#039;5 minutes&amp;#039;)&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;session_window(ts, &amp;#039;30 minutes&amp;#039;)&amp;lt;/code&amp;gt; in the &amp;lt;code&amp;gt;GROUP BY&amp;lt;/code&amp;gt; clause.&lt;br /&gt;
&lt;br /&gt;
== Windowing in other engines ==&lt;br /&gt;
[[Apache Flink]]&amp;#039;s DataStream API defines windows with a &amp;#039;&amp;#039;&amp;#039;window assigner&amp;#039;&amp;#039;&amp;#039;. It ships assigners for tumbling, sliding, session and &amp;#039;&amp;#039;&amp;#039;global&amp;#039;&amp;#039;&amp;#039; windows; a global window puts all records of a key into one window and computes nothing unless a custom trigger is set. Tumbling and sliding assigners take an optional offset, similar to Spark&amp;#039;s &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;flink-win&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/windows/ |title=Windows (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Flink SQL uses windowing table-valued functions (TVFs): &amp;lt;code&amp;gt;TUMBLE&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HOP&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;CUMULATE&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt;. Each adds &amp;lt;code&amp;gt;window_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; columns, where &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; equals &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt; minus 1 millisecond. The session TVF is supported only in streaming mode. Windowing TVFs replace the older grouped window functions.&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/window-tvf/ |title=Windowing table-valued functions (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kafka Streams names its window types differently. It has hopping, tumbling, sliding and session windows; hopping and tumbling windows are aligned to the epoch, with an inclusive lower bound and an exclusive upper bound. A Kafka Streams &amp;#039;&amp;#039;&amp;#039;sliding window&amp;#039;&amp;#039;&amp;#039; is not the same as a Spark sliding window: it is aligned to record timestamps, both bounds are inclusive, and it is used for joins (&amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;) and for &amp;lt;code&amp;gt;SlidingWindows&amp;lt;/code&amp;gt; aggregations. The Kafka documentation notes that what other tools call sliding windows, Kafka Streams calls hopping windows.&amp;lt;ref name=&amp;quot;kstreams&amp;quot;&amp;gt;{{Cite web |url=https://kafka.apache.org/44/streams/developer-guide/dsl-api/ |title=Kafka Streams DSL (Apache Kafka 4.4) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Window type !! Spark Structured Streaming !! Apache Flink DataStream !! Apache Flink SQL !! Kafka Streams&lt;br /&gt;
|-&lt;br /&gt;
! Fixed, non-overlapping&lt;br /&gt;
| &amp;lt;code&amp;gt;window(ts, size)&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TumblingEventTimeWindows&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;TumblingProcessingTimeWindows&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;TUMBLE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Tumbling time window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Fixed, overlapping&lt;br /&gt;
| &amp;lt;code&amp;gt;window(ts, size, slide)&amp;lt;/code&amp;gt; (sliding)&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Sliding window assigners&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;HOP&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Hopping time window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Gap-based&lt;br /&gt;
| &amp;lt;code&amp;gt;session_window(ts, gap)&amp;lt;/code&amp;gt;, static or per-row gap&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Session window assigners, static gap or &amp;lt;code&amp;gt;SessionWindowTimeGapExtractor&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;SESSION&amp;lt;/code&amp;gt;, streaming only, static gap&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Session window&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Other types&lt;br /&gt;
| None built in&lt;br /&gt;
| Global windows with a custom trigger&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;CUMULATE&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Sliding windows based on record time differences&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Window bounds&lt;br /&gt;
| Start inclusive, end exclusive, aligned to the Unix epoch with an optional &amp;lt;code&amp;gt;startTime&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Aligned to the epoch, optional offset&amp;lt;ref name=&amp;quot;flink-win&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;window_start&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_end&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; columns&amp;lt;ref name=&amp;quot;flink-tvf&amp;quot; /&amp;gt;&lt;br /&gt;
| Hopping and tumbling aligned to the epoch; sliding aligned to records&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Session window]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Event time and processing time]]&lt;br /&gt;
* [[Output mode]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Stream processing]]&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:Pipelines and orchestration]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>