<?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=Stream-stream_join</id>
	<title>Stream-stream join - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Stream-stream_join"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Stream-stream_join&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=Stream-stream_join&amp;diff=211&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=Stream-stream_join&amp;diff=211&amp;oldid=prev"/>
		<updated>2026-11-25T00:53:01Z</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            = Stream-stream join&lt;br /&gt;
| also_known_as   = Streaming join, interval join (Flink)&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 2.3&lt;br /&gt;
| key_parts       = Two streaming inputs, join keys, [[watermark]] on each input, event-time range or window condition, buffered state&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]], [[Apache Flink]] (interval join, regular join), Kafka Streams (&amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;)&lt;br /&gt;
| related         = [[Stream-static join]], [[Watermark]], [[State store]], [[Stateful stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (join operations, support matrix, recovery semantics) and Real-time Mode guide, the Apache Flink 2.3 DataStream &amp;quot;Joining&amp;quot; and SQL &amp;quot;Joins&amp;quot; pages, and the Kafka Streams 4.4 DSL developer guide}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;stream-stream join&amp;#039;&amp;#039;&amp;#039; joins two streaming DataFrames, so that each new row from one stream is matched with rows that have arrived, or will arrive, on the other. Because a match can come later, Spark buffers past rows of both inputs as state; [[watermark]]s on both inputs and a time condition in the join let Spark drop buffered rows that can no longer match, so that state does not grow without limit. Spark added stream-stream joins in Spark 2.3.&amp;lt;ref name=&amp;quot;ss-join&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-stream-joins |title=Structured Streaming: Stream-stream Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The result of the join is the same as a batch join over the same data.&amp;lt;ref name=&amp;quot;ss-joinops&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#join-operations |title=Structured Streaming: Join Operations (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why does a stream-stream join need state? ==&lt;br /&gt;
At any moment, both sides of a stream-stream join are incomplete. A row received now on one input can match a row that the other input has not received yet. Spark therefore keeps past input from both streams in the [[state store]], matches every new row against it, and handles late and out-of-order data the same way as for aggregations.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without limits, all past input must be kept, because any new row could match any old one.&amp;lt;ref name=&amp;quot;ss-inner&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#inner-joins-with-optional-watermarking |title=Structured Streaming: Inner Joins with optional Watermarking (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In a long-running query, that state grows until the query fails or slows down.&lt;br /&gt;
&lt;br /&gt;
== How do watermarks and time constraints bound state? ==&lt;br /&gt;
To let Spark clear old rows, a join needs two things:&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&amp;gt;&lt;br /&gt;
# a watermark on both inputs, saying how late each input&amp;#039;s data can be; and&lt;br /&gt;
# an event-time constraint between the inputs, so that Spark can tell when an old row of one input can no longer match the other. The constraint is either a time range, such as &amp;lt;code&amp;gt;leftTime BETWEEN rightTime AND rightTime + INTERVAL 1 HOUR&amp;lt;/code&amp;gt;, or a join on event-time windows, such as &amp;lt;code&amp;gt;leftTimeWindow = rightTimeWindow&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
With both, the rows kept for each side are roughly those within the other side&amp;#039;s watermark delay plus the width of the time range. The guarantee follows the watermark rule: with a 2-hour watermark, no row less than 2 hours late is dropped, but a row later than that may or may not be processed.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
The Spark guide&amp;#039;s example joins ad impressions with ad clicks. Impressions can be up to 2 hours late, clicks up to 3 hours late, and a click counts if it happens within 1 hour after its impression.&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql.functions import expr&lt;br /&gt;
&lt;br /&gt;
impressions = spark.readStream.table(&amp;quot;main.ads.impressions&amp;quot;)   # impressionAdId, impressionTime&lt;br /&gt;
clicks = spark.readStream.table(&amp;quot;main.ads.clicks&amp;quot;)             # clickAdId, clickTime&lt;br /&gt;
&lt;br /&gt;
joined = (impressions.withWatermark(&amp;quot;impressionTime&amp;quot;, &amp;quot;2 hours&amp;quot;)&lt;br /&gt;
    .join(&lt;br /&gt;
        clicks.withWatermark(&amp;quot;clickTime&amp;quot;, &amp;quot;3 hours&amp;quot;),&lt;br /&gt;
        expr(&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
            clickAdId = impressionAdId AND&lt;br /&gt;
            clickTime &amp;gt;= impressionTime AND&lt;br /&gt;
            clickTime &amp;lt;= impressionTime + interval 1 hour&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;),&lt;br /&gt;
        &amp;quot;leftOuter&amp;quot;,&lt;br /&gt;
    ))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Which join types are supported? ==&lt;br /&gt;
Inner joins are supported on any columns and conditions; watermarks and time constraints are optional, but without them state is unbounded. Outer and semi joins require them, because Spark must know when a row will never match in order to emit the outer row with nulls, or to evict an unmatched left row.&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt; The support matrix in Spark 4.3.0:&amp;lt;ref name=&amp;quot;ss-matrix&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#support-matrix-for-joins-in-streaming-queries |title=Structured Streaming: Support matrix for joins in streaming queries (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Join type !! Requirement&lt;br /&gt;
|-&lt;br /&gt;
| Inner || Supported; watermarks on both sides and a time constraint are optional and enable state cleanup&lt;br /&gt;
|-&lt;br /&gt;
| Left outer || Watermark on the right side and a time constraint required; left watermark optional, for full cleanup&lt;br /&gt;
|-&lt;br /&gt;
| Right outer || Watermark on the left side and a time constraint required; right watermark optional&lt;br /&gt;
|-&lt;br /&gt;
| Full outer || Watermark on one side and a time constraint required; the other watermark optional&lt;br /&gt;
|-&lt;br /&gt;
| Left semi || Watermark on the right side and a time constraint required; left watermark optional&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Other rules apply. Joins can be chained (&amp;lt;code&amp;gt;df1.join(df2, ...).join(df3, ...)&amp;lt;/code&amp;gt;), and a query with a stream-stream join must use append [[output mode]]. &amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; cannot be used before or after a join, but in append mode aggregations, deduplication and other joins can.&amp;lt;ref name=&amp;quot;ss-matrix&amp;quot; /&amp;gt; Changing the join type, the equi-join columns or the input schema is not allowed between restarts from the same [[streaming checkpoint]].&amp;lt;ref name=&amp;quot;ss-changes&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovery-semantics-after-changes-in-a-streaming-query |title=Structured Streaming: Recovery Semantics after Changes in a Streaming Query (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Stream-stream joins are not supported in Real-time Mode as of Spark 4.3.0.&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;
== Why are outer join results delayed? ==&lt;br /&gt;
An outer row with nulls is emitted only after Spark is sure no match will arrive, so its delay depends on the watermark delay and the time range. In the micro-batch engine, the watermark advances at the end of a batch and the next batch uses it to clean state and emit outer rows. Since a batch runs only when there is new data, outer output can be held back if either input stops receiving data for a while.&amp;lt;ref name=&amp;quot;ss-outer&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#outer-joins-with-watermarking |title=Structured Streaming: Outer Joins with 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;
== Stream-stream joins in other engines ==&lt;br /&gt;
[[Apache Flink]]&amp;#039;s DataStream API has an &amp;#039;&amp;#039;&amp;#039;interval join&amp;#039;&amp;#039;&amp;#039;: elements of stream B with the same key match an element of stream A when &amp;lt;code&amp;gt;a.timestamp + lowerBound &amp;lt;= b.timestamp &amp;lt;= a.timestamp + upperBound&amp;lt;/code&amp;gt;. It supports only inner joins.&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/dev/datastream/operators/joining/ |title=Joining (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 distinguishes &amp;#039;&amp;#039;&amp;#039;regular joins&amp;#039;&amp;#039;&amp;#039;, which keep both inputs in state forever unless a state TTL is configured (which can affect correctness), from &amp;#039;&amp;#039;&amp;#039;interval joins&amp;#039;&amp;#039;&amp;#039;, which need at least one equi-join predicate and a condition that bounds time on both sides.&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/sql/reference/queries/joins/ |title=Joins (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; A Spark join with a time-range condition and watermarks corresponds to an interval join; a Spark inner join without them corresponds to a regular join without TTL.&lt;br /&gt;
&lt;br /&gt;
Kafka Streams uses &amp;lt;code&amp;gt;JoinWindows&amp;lt;/code&amp;gt;, a sliding window over record timestamps, for windowed stream-stream joins.&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;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark stream-stream join !! Flink DataStream interval join !! Flink SQL interval join !! Flink SQL regular join&lt;br /&gt;
|-&lt;br /&gt;
! Time bound&lt;br /&gt;
| Optional for inner, required for outer and semi&amp;lt;ref name=&amp;quot;ss-join&amp;quot; /&amp;gt;&lt;br /&gt;
| Required (lower and upper bound)&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot; /&amp;gt;&lt;br /&gt;
| Required on both sides&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
| None&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Can state grow without limit?&lt;br /&gt;
| Yes, for an inner join without watermarks and a time constraint&amp;lt;ref name=&amp;quot;ss-inner&amp;quot; /&amp;gt;&lt;br /&gt;
| No; the time bounds are part of the join&amp;lt;ref name=&amp;quot;flink-dsjoin&amp;quot; /&amp;gt;&lt;br /&gt;
| No; the time condition is required&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
| Yes, unless a state TTL is configured&amp;lt;ref name=&amp;quot;flink-sqljoin&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Stream-static join]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[State store]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Output mode]]&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;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>