Skip to content

[SPARK-58904][SS] Enforce correct watermark placement for stream-stream left semi and left outer joins - #58238

Open
ganeshashree wants to merge 1 commit into
apache:masterfrom
ganeshashree:SPARK-58904
Open

[SPARK-58904][SS] Enforce correct watermark placement for stream-stream left semi and left outer joins#58238
ganeshashree wants to merge 1 commit into
apache:masterfrom
ganeshashree:SPARK-58904

Conversation

@ganeshashree

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Stream-stream left semi and left outer joins rely on the left-side state being evicted by the watermark, but the analyzer did not require the watermark to be placed where that eviction can happen. This adds a shared analyzer check, checkStreamStreamJoinWatermarkPlacement, with two requirements:

(1) left-state eviction for both types (the equi eviction key must be watermarked, or the range bound must sit between watermarked attributes on both sides);
(2) for left outer only, both eviction-ordinal join keys must be watermarked so a late row cannot invalidate an already-emitted unmatched row. The new helpers mirror the runtime's own attribute selection so the analyzer rejects exactly the placements the runtime cannot honor.

It is gated by a kill switch, spark.sql.streaming.join.stricterWatermarkRequirements.enabled (default true), to restore the previous behavior. This is the shared-code fix split out of #57813 (SPARK-58611, left anti).

Why are the changes needed?

With only the right side watermarked, or the watermark on the wrong join-key ordinal or an unrelated attribute, the runtime builds no left-eviction predicate. Left outer then silently drops its unmatched output, and left semi state grows without bound. These placements should be rejected at analysis time rather than run incorrectly.

Does this PR introduce any user-facing change?

Yes. Some stream-stream left semi and left outer queries that previously ran now fail with an AnalysisException explaining the required watermark placement. The behavior can be reverted with spark.sql.streaming.join.stricterWatermarkRequirements.enabled=false.
Documented in the Structured Streaming migration guide (4.3 to 4.4).

How was this patch tested?

Added analyzer tests in UnsupportedOperationsSuite (range both-sides, right-only, unrelated attribute, constant and anti-monotonic bounds, multiple event-time columns, one-sided and both-sided equi keys, composite keys, kill-switch fallback) and runtime tests in StreamingJoinSuite for left outer and left semi. Ran locally: UnsupportedOperationsSuite (261) and StreamingOuterJoinWithoutVCFSuite + StreamingLeftSemiJoinWithoutVCFSuite (74), all pass.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

…am left semi and left outer joins

Stream-stream left semi and left outer joins rely on left-side state being
evicted by the watermark, but the analyzer accepted placements that leave it
un-evicted: left outer silently dropped its unmatched output and left semi state
grew without bound when only the right side (or the wrong attribute) was
watermarked.

Add a shared analyzer check, checkStreamStreamJoinWatermarkPlacement:
- Left-state eviction: the equi eviction key must be watermarked, or the range
  bound must sit between watermarked attributes on both sides.
- Left outer additionally requires both eviction-ordinal join keys to be
  watermarked, so a late row cannot invalidate an already-emitted unmatched row.

Because this rejects queries that previously ran, it is gated by
spark.sql.streaming.join.stricterWatermarkRequirements.enabled (default true);
set it to false to restore the previous behavior. The migration guide and join
docs are updated. Right outer and full outer are out of scope.
@uros-b

uros-b commented Aug 24, 2026

Copy link
Copy Markdown
Member

Thank you @ganeshashree! cc @HeartSaVioR for SS

@uros-b
uros-b requested a review from HeartSaVioR August 24, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants