HeartSaVioR opened a new pull request, #60705:
URL: https://github.com/apache/spark/pull/60705
### What changes were proposed in this pull request?
A stream-stream join can bound one input's state only through a column cast
to TIMESTAMP, such
as a DATE, TIMESTAMP_NTZ or numeric column. The cutoff is solved for the
cast, but the state is
evicted by the input's event time. This PR evicts such state by the cast
itself:
- The column pick of #60667 also takes a cast of an input column to
TIMESTAMP that the condition
bounds, after the event time and other TIMESTAMP columns. It keeps the
cast as it is in the
condition, so eviction uses the same session time zone.
- State formats 1 to 3 evict rows where `cast <= cutoff`, and rows where the
cast is NULL.
- State format 4 orders the state of that input by the value of the cast.
The V4 index version
moves to 2 because index versions 0 and 1 order such state by the event
time, so a join with
such an input fails to restart from them with
`STREAMING_JOIN_STATE_V4_CHECKPOINT_INCOMPATIBLE`
instead of evicting the wrong rows.
This PR is stacked on #60667. Please review only its own commit.
### Why are the changes needed?
Eviction by the event time drops rows that later rows of the other input can
still match.
Example, with 1 hour watermarks on `leftTime` and `rightTime`:
```sql
SELECT * FROM l LEFT OUTER JOIN r
ON leftKey = rightKey
AND rightTime BETWEEN leftTime AND CAST(leftDate AS TIMESTAMP)
```
| Step | Input | Before this PR | With this PR |
|---|---|---|---|
| 1 | left (1, leftTime = day 1, leftDate = day 5); right (9, day 1) | - | -
|
| 2 | left (8, day 5 03:00, day 9); right (9, day 5 03:00) | - | - |
| 3 | right (9, day 5 03:00); the watermark is now day 5 02:00 | `(1, null,
day 1)`: the row is evicted by `leftTime` | - |
| 4 | right (1, day 5 05:00) | - | `(1, day 5 05:00, day 1)` |
The times are in UTC, with session time zone `America/Los_Angeles`, so the
range ends at
day 5 08:00 UTC. An inner join loses the match the same way.
### Does this PR introduce _any_ user-facing change?
Yes. Such joins keep the rows until the cast passes the cutoff, so they
return the matches and
emit outer join rows at the right time. With state format 4, a join with
such an input cannot
restart from a checkpoint of an earlier version; start it with a new
checkpoint. The migration
guide entry of #60667 now covers casts.
### How was this patch tested?
New tests in `StreamingJoinRangeEvictionSuite`: the example above with state
formats 2, 3 and 4,
inner and left outer (all fail before this PR), and a V4 test that index
versions 0 and 1 fail
for a cast-bounded input. `StreamingJoinHelperSuite` now expects a
TIMESTAMP_NTZ cast to be
picked. The stream-stream join 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]