[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
Open
[SPARK-58904][SS] Enforce correct watermark placement for stream-stream left semi and left outer joins#58238ganeshashree wants to merge 1 commit into
ganeshashree wants to merge 1 commit into
Conversation
…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
approved these changes
Aug 24, 2026
Member
|
Thank you @ganeshashree! cc @HeartSaVioR for SS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
AnalysisExceptionexplaining the required watermark placement. The behavior can be reverted withspark.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 inStreamingJoinSuitefor left outer and left semi. Ran locally:UnsupportedOperationsSuite(261) andStreamingOuterJoinWithoutVCFSuite+StreamingLeftSemiJoinWithoutVCFSuite(74), all pass.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)