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

   ### What changes were proposed in this pull request?
   
   **Stack.** This is PR 8 of 8 and depends on #60286. Until the earlier PRs 
merge, this PR also shows their commits, and the merge commits bring in their 
changes. Please review only this PR's own commit: 
[fea067db51b](https://github.com/apache/spark/pull/PRNUM/commits/fea067db51b8edd7d849d6738a6f6be7f03a5de0).
 Merge order:
   
   1. #60279 [SPARK-61344](https://issues.apache.org/jira/browse/SPARK-61344): 
Fix stream-stream join range eviction column and output watermark
   2. #60280 [SPARK-61345](https://issues.apache.org/jira/browse/SPARK-61345): 
Fix stream-stream join watermark direction and equality-key eviction
   3. #60281 [SPARK-61346](https://issues.apache.org/jira/browse/SPARK-61346): 
Derive stream-stream join range eviction from the late-filtering event time
   4. #60282 [SPARK-61347](https://issues.apache.org/jira/browse/SPARK-61347): 
Evict stream-stream join range state without a watermark on the stored side
   5. #60283 [SPARK-61348](https://issues.apache.org/jira/browse/SPARK-61348): 
Reject non-timestamp range bounds in stream-stream outer and semi joins
   6. #60284 [SPARK-61349](https://issues.apache.org/jira/browse/SPARK-61349): 
Ignore constant-only bounds in stream-stream join state eviction
   7. #60286 [SPARK-61350](https://issues.apache.org/jira/browse/SPARK-61350): 
Reject negative watermark terms in stream-stream join eviction bounds
   8. [SPARK-61514](https://issues.apache.org/jira/browse/SPARK-61514): Derive 
V4 stream-stream join scan windows from the incoming row (this PR)
   
   Until #60307 
([SPARK-61380](https://issues.apache.org/jira/browse/SPARK-61380)) merges, step 
1 (#60279) also carries its change. Until #60378 
([SPARK-61513](https://issues.apache.org/jira/browse/SPARK-61513)) merges, this 
PR also carries it through merge commits; this PR replaces the scan that #60378 
guards, so the merges keep this PR's code.
   
   In state format version 4, each side's state is ordered by a timestamp: an 
equality key, the column the side's value-eviction predicate constrains, or its 
event time. A new row reads the other side's rows for its key. This PR gives 
every such read a window on the column the other side is actually ordered by, 
computed from the new row:
   
   - `MatchingScanWindow` takes the deterministic comparisons of the join 
condition (`>=`, `>`, `<=`, `<`, `=`, BETWEEN) in which one side reaches the 
ordering column and the other side reads only the new row's input. It evaluates 
the other side on the row and keeps the highest lower bound and the lowest 
upper bound.
   - The column may be shifted by an interval without days or months, cast to 
BIGINT (whole seconds, inverted exactly), or added to a BIGINT term that cannot 
wrap around. Any other expression of the column gives no bound.
   - A NULL bound, one that fails to evaluate, or one that overflows leaves its 
end open. A strict comparison gives an inclusive bound; the join still checks 
the full condition.
   - `StreamingSymmetricHashJoinExec.matchingScanWindow(side)` picks the column 
from the other side's layout, using 
`SymmetricHashJoinStateManager.valueTimestampColumnOrdinal`, which the V4 state 
manager now shares. A side ordered by an equality key gets no window, as before.
   - `getValuesInRange` range-scans a window open at the top: it scans up to 
`Long.MaxValue`, then reads the values at `Long.MaxValue` by key. A window 
whose ends cross reads nothing.
   - This replaces the window built from the watermark solver's constant 
offsets, and the check that turned it off for both sides unless both were 
ordered by their event times.
   
   For Nexmark q9 (`bid.dateTime BETWEEN auction.dateTime AND 
auction.expires`), the auction side is ordered by `expires`. An auction row now 
reads bids with `dateTime` in `[auction.dateTime, auction.expires]`, and a bid 
row reads auctions with `expires >= bid.dateTime`. Before, both read all rows 
for the key.
   
   ### Why are the changes needed?
   
   V4 read all state rows for a key whenever the condition bounded a time by 
another column, as in q9. Such queries could be slower in V4 than in V2. The 
old window could also miss matches: the solver counts a day as 24 hours, so 
with `rightTime BETWEEN leftTime AND leftTime + INTERVAL 1 DAY` in a time zone 
with daylight saving time, a right row 24.5 hours after a left row was skipped 
on a 25-hour day.
   
   ### Does this PR introduce _any_ user-facing change?
   
   V4 joins read fewer state rows for conditions like q9. They now also emit 
matches across a daylight saving time change, which the old window missed for 
whole-day intervals. V1 to V3, the V4 state layout, eviction and checkpoints do 
not change.
   
   ### How was this patch tested?
   
   - New `MatchingScanWindowSuite`, with unit tests for each bound kind: 
BETWEEN, strict and equal comparisons, exact shifts, days and months across 
DST, BIGINT casts on both sides, differences, unsupported expressions, NULL, 
failing and overflowing bounds, and ANSI, TRY and LEGACY sums.
   - V4 tests that check the results and the windows of the executed plan in 
both directions for q9 and for a one-sided range.
   - Inner, left outer, full outer and left semi tests on the q9 shape, and an 
inner join with whole days across DST, in every state format version.
   - A state manager test for a range open at the top.
   - The left semi test with a truncating cast now also runs in V4.
   - The DST test failed in V4 before this change.
   
   build/sbt 'catalyst/testOnly *StreamingJoinHelperSuite'  # 9 passed
   build/sbt 'sql/testOnly *MatchingScanWindowSuite 
*SymmetricHashJoinStateManagerSuite 
*SymmetricHashJoinStateManagerEventTimeInValueSuite 
*SymmetricHashJoinStateManagerEventTimeInKeySuite 
*StreamingSymmetricHashJoinHelperSuite'  # 104 passed
   build/sbt 'sql/testOnly *StreamingInnerJoinV4Suite 
*StreamingOuterJoinV4Suite *StreamingFullOuterJoinV4Suite 
*StreamingLeftSemiJoinV4Suite'  # 291 passed
   build/sbt 'sql/testOnly *StreamingInnerJoinWithVCFSuite 
*StreamingInnerJoinWithoutVCFSuite *StreamingOuterJoinWithVCFSuite 
*StreamingOuterJoinWithoutVCFSuite *StreamingFullOuterJoinWithVCFSuite 
*StreamingFullOuterJoinWithoutVCFSuite *StreamingLeftSemiJoinWithVCFSuite 
*StreamingLeftSemiJoinWithoutVCFSuite -- -z "another column of the left input" 
-z "daylight saving" -z "truncating cast"'  # 28 passed
   
   Scalastyle for catalyst and sql, main and test sources: 0 errors.
   
   A small local benchmark of the q9 shape (RocksDB, 8 batches of 500 auctions 
and 5,000 bids on 50 keys, state growing): the windows read about 12 times 
fewer state rows (266,382 instead of 3,200,000), and the last four batches took 
2.5 to 3.5 s instead of 4.8 s (V4 before) and 7.8 to 8.4 s (V2). These are 
single runs on a shared host.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Anthropic 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