HeartSaVioR opened a new pull request, #60666:
URL: https://github.com/apache/spark/pull/60666
### What changes were proposed in this pull request?
An outer or left semi stream-stream join outputs some rows only once:
unmatched rows with NULLs,
or left semi matches. Such a row is final only if no later row of the other
input can still match
it. Today's analysis check accepts any watermarked equality key, whichever
input it is on. This
PR adds a check: the other input's watermark must bound the state. It can do
that through the
equality key that eviction uses (the watermarked column, or that column
shifted forward by a
constant), or through a range condition. Full outer joins need this for both
inputs. The internal
conf `spark.sql.streaming.join.checkWatermarkDirection.enabled` (default
true) turns the check off.
### Why are the changes needed?
```scala
val left = leftDf.withWatermark("lt", "10 seconds") // right has no
watermark
left.join(rightDf, expr("lk = rk AND lt = rt"), "left_outer")
```
The left watermark evicts left `(1, 5)` and emits `(1, 5, null)`. A right
row `(1, 5)` that
arrives later is not late, because the right input has no watermark. It
matches nothing, so the
correct result `(1, 5, 5)` is lost. A backward-shifted key (`lt = rt -
INTERVAL 10 SECONDS`) loses
matches the same way. The join support table already requires the other
input's watermark.
### Does this PR introduce _any_ user-facing change?
Yes. Such queries now fail analysis instead of producing wrong results. The
migration guide
explains how to restore the earlier check. The support table now says a full
outer join needs
watermarks on both inputs.
### How was this patch tested?
New rows in `UnsupportedOperationsSuite` for each join type, including
one-sided watermarks,
forward and backward key shifts, and the conf turned off. New
`StreamingJoinWatermarkDirectionSuite`
for the example above. On master, all new "not supported" rows and the new
suite fail.
In scope: the analysis check. Out of scope: eviction changes, such as
per-input key ordinals or
evicting inputs without their own watermark.
### Note for reviewers, including AI review
Please review only the changes in this PR. For each finding, please give a
runnable reproducer
and say whether master has the same behavior.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude (Opus 5.5)
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]