HeartSaVioR opened a new pull request, #60713:
URL: https://github.com/apache/spark/pull/60713

   ### What changes were proposed in this pull request?
   
   A stream-stream join forwards its input watermark as its output watermark, 
even when the state of
   one input has no cutoff. A stored row of that input can then join a later 
row and emit an old
   event time, and a stateful operator after the join drops it as late. This PR 
rejects such a query:
   in append mode, a stateful operator after a stream-stream join fails when an 
input of the join
   with a watermarked column has no state cutoff, that is, no watermark in the 
join keys, and no
   range condition that bounds the input by the other input's watermark. It 
uses the same derivation
   as state eviction. An input without a watermarked column cannot emit a late 
event time, so it is
   not checked.
   
   The check reuses the correctness check of chained stateful operators:
   `spark.sql.streaming.statefulOperator.checkCorrectness.enabled` set to false 
only logs a warning.
   The error names the input. The check runs when the first batch is planned, 
after the confs of the
   checkpoint are restored, so a query restarted from a checkpoint of an 
earlier version keeps
   running and only logs the warning. An internal conf recorded in the offset 
log does this.
   
   ### Why are the changes needed?
   
   The query returns a wrong result silently. Example, with 10 second 
watermarks on both inputs:
   
   ```scala
   left.join(right, expr("leftKey = rightKey"))
     .groupBy(window($"leftTime", "10 seconds")).count()   // append mode
   ```
   
   | Batch | Input (key, seconds) | Before this PR |
   |---|---|---|
   | 0 | left (1, 5), (2, 5); right (2, 5), (9, 5) | (2, 5) joins |
   | 1 | left (3, 30); right (8, 30) | the watermark becomes 20 s |
   | 2 | right (7, 31) | window [0, 10) is emitted with count 1, as final |
   | 3 | right (1, 40) | joins the stored left (1, 5); the aggregation drops it 
as late |
   
   The batch answer is count 2. The same happens with
   `leftKey = rightKey AND rightTime <= leftTime + INTERVAL 10 SECONDS` and a 
window on `rightTime`,
   because the right input has no cutoff. With this PR, both queries fail when 
the first batch is
   planned, naming the left and the right input.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. A new streaming query of this shape fails when its first batch is 
planned. Add a watermark in
   the join keys, or a range condition that bounds each input by the other 
input's watermark, or set
   `spark.sql.streaming.statefulOperator.checkCorrectness.enabled` to false. 
Queries restarted from
   an existing checkpoint only log a warning.
   
   Known limits:
   - The rule is coarse: it does not trace which input's event time the later 
operator uses, so
     the second example is rejected even with a window on `leftTime`, the 
bounded side. Setting
     `spark.sql.streaming.statefulOperator.checkCorrectness.enabled` to false 
runs such a query.
   - Only new checkpoints are checked. A query restarted from an existing 
checkpoint logs a warning.
   - The query fails when its first batch is planned, not when it starts.
   - Update mode is not checked.
   - Inputs evicted by another column (after #60667) are left to a follow-up.
   
   ### How was this patch tested?
   
   New `StreamingJoinOutputWatermarkSuite`, state format versions 2 and 4:
   - both examples above are rejected (they fail before this PR),
   - a time-interval join and a join on watermarked windows before a window 
aggregation still run,
   - with the correctness check disabled, the first example runs and logs the 
warning,
   - a restart from a checkpoint without the new conf in its offset log keeps 
running.
   
   The join, multiple stateful operator and offset log suites pass.
   
   ### Note for reviewers, including AI review
   
   Please review only this PR's own commit. For each finding, 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]

Reply via email to