Jump to content

Stream-static join

From Open Lakehouse Wiki
Stream-static join
Also known as Stream-table join, stream enrichment join
Field Stream processing
Introduced Apache Spark 2.0
Key parts A streaming DataFrame, a static (batch) DataFrame or table, join keys; no streaming state
Open source implementations Structured Streaming in Apache Spark; related forms in Apache Flink SQL (temporal and lookup joins)
Related Stream-stream join, Delta Lake, Broadcast join, Stateful stream processing
Last verified 23 November 2026 against the Spark 4.3.0 Structured Streaming programming guide (join operations, support matrix) and Real-time Mode guide, the Databricks "Work with joins" page, and the Apache Flink 2.3 SQL "Joins" page.

In Apache Spark Structured Streaming, a stream-static join joins a streaming DataFrame with a static DataFrame, for example a stream of orders with a table of customers. Each micro-batch of the stream is joined with the static side, and the join keeps no streaming state, so it needs no watermark. Structured Streaming has supported stream-static joins, inner and some outer types, since Spark 2.0.[1] It is the usual way to enrich events with reference or dimension data held in a lakehouse table.

How does a stream-static join work?

The static side is an ordinary batch DataFrame read with spark.read, and the streaming side comes from spark.readStream. The join is written like a batch join:[1]

customers = spark.read.table("main.crm.customers")          # static side
orders = spark.readStream.table("main.sales.orders")       # streaming side

enriched = orders.join(customers, "customer_id", "left_outer")

(enriched.writeStream
    .option("checkpointLocation", "/checkpoints/orders_enriched")
    .toTable("main.sales.orders_enriched"))

Because only the streaming side changes, each batch's new rows are joined with the static data and the result is final; nothing is buffered for later matches. The Spark guide states that stream-static joins are not stateful and need no state management.[1] This is the main difference from a stream-stream join, which buffers both inputs.

Which join types are supported?

The support matrix in Spark 4.3.0 allows only the join types in which the streaming side's rows can be completed from the static side alone:[2]

Left input Right input Inner Left outer Right outer Full outer Left semi
Stream Static Yes Yes No No Yes
Static Stream Yes No Yes No No

The unsupported types would need to emit a static row once it is clear that no streaming row will ever match it, which cannot be known for an unbounded stream without state.

How is the static side refreshed?

The Databricks documentation, for a static side stored in Delta Lake, states that each micro-batch joins the latest valid version of the static Delta table with the records of that micro-batch. The static table should therefore change slowly. If it changes between runs, reprocessing the same streaming data can give different results, so the output is not deterministic while the static side is changing.[3]

Rows already written are not revised when the static side changes later. An order joined with a customer's old address keeps the old address in the output, because the join keeps no state with which to revisit it.[1] Pipelines that need updates on both sides use a stream-stream join or a materialized view instead; Databricks recommends a materialized view for incremental results of an inner join.[3]

Stream-static joins in Real-time Mode

Real-time Mode, added in Spark 4.1.0, supports stream-static joins only when the static side is broadcast with the broadcast(...) hint, because the join must not add a shuffle.[4]

from pyspark.sql.functions import broadcast

enriched = orders.join(broadcast(customers), "customer_id")

In micro-batch mode the hint is optional and follows the usual join strategy rules.

Stream-static join vs stream-stream join

Stream-static join Stream-stream join
Inputs One streaming, one batch DataFrame[1] Two streaming DataFrames[5]
State None[1] Both inputs buffered in the state store[5]
Watermark Not needed[3] Needed to bound state; required for outer and semi joins[5]
Since Spark 2.0[1] Spark 2.3[5]
Real-time Mode (Spark 4.3.0) Supported with a broadcast static side[4] Not supported[4]

Comparison with Flink

Apache Flink SQL has two related joins. A temporal join joins against a versioned table, so that each row can be matched with the version valid at its event time. A lookup join enriches a table with data queried from an external system; one side needs a processing-time attribute and the other must be backed by a lookup source connector.[6] A Spark stream-static join against a Delta table is closest to a processing-time lookup: each batch sees the table as it is when the batch runs.[3]

See also

References

  1. ↑ 1.0 1.1 1.2 1.3 1.4 1.5 1.6 Structured Streaming: Stream-static Joins (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  2. ↑ Structured Streaming: Support matrix for joins in streaming queries (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  3. ↑ 3.0 3.1 3.2 3.3 Work with joins on Databricks. Databricks.Retrieved 2026-11-23.
  4. ↑ 4.0 4.1 4.2 Real-time Mode (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  5. ↑ 5.0 5.1 5.2 5.3 Structured Streaming: Stream-stream Joins (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.