HeartSaVioR opened a new pull request, #60280: URL: https://github.com/apache/spark/pull/60280
### What changes were proposed in this pull request? This PR checks the direction of each watermark when a stream-stream join is admitted, and evicts equality-key state with the opposite input's watermark. **Stack.** This is PR 2 of 7 and depends on #60279. Until the earlier PRs merge, this PR also shows their commits. Please review only the last commit, `963f9bb3a4b`. 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. (PR to follow) [SPARK-61345](https://issues.apache.org/jira/browse/SPARK-61345): Fix stream-stream join watermark direction and equality-key eviction (this PR) 3. (PR to follow) [SPARK-61346](https://issues.apache.org/jira/browse/SPARK-61346): Derive stream-stream join range eviction from the late-filtering event time 4. (PR to follow) [SPARK-61347](https://issues.apache.org/jira/browse/SPARK-61347): Evict stream-stream join range state without a watermark on the stored side 5. (PR to follow) [SPARK-61348](https://issues.apache.org/jira/browse/SPARK-61348): Reject numeric state bounds in stream-stream outer joins 6. (PR to follow) [SPARK-61349](https://issues.apache.org/jira/browse/SPARK-61349): Ignore constant-only bounds in stream-stream join state eviction 7. (PR to follow) [SPARK-61350](https://issues.apache.org/jira/browse/SPARK-61350): Reject negative watermark terms in stream-stream join eviction bounds - **Directional admission.** Check the direction of each watermark before admitting a streaming outer or left semi join. The rows a side finalizes need a bound derived from the opposite input's watermark. Full outer joins need a bound in both directions. - **Opposite-side equality eviction.** Derive each side's equality-key eviction predicate and V4 timestamp index from the opposite input's event-time key, which can sit at a different equality-key ordinal. A key that is the opposite event time shifted by a constant interval, such as `lt = rt + INTERVAL 10 SECONDS`, is bounded by the watermark plus that interval, for either sign. The output watermark uses the same relation. A truncating key such as `CAST(CAST(rt AS BIGINT) AS TIMESTAMP)` gets no key bound, because a later row can truncate below the watermark. A shift of a day or more qualifies only in a fixed-offset time zone, because Spark adds whole days in the session time zone, where a day can be 23 or 25 hours. - **Null keys in V4.** A selected key, window or window end can be null. Keep those rows in the primary state but out of the timestamp eviction index, because the key-watermark predicate cannot evict a null timestamp. Lookup, removal and recovery are unchanged. - **Checkpoint version 2.** For older V4 checkpoints, an aligned own-event-time equality key is accepted only when the selected timestamp is provably non-null on both sides. A `window()` key qualifies when its struct is non-null, because `window()` computes the end from a non-null event time. V1 to V3 keep the existing rule. A shifted key is not accepted for old checkpoints, because older versions evicted it at the unshifted watermark. - **Docs.** The migration guide and the join support table describe the required watermark direction. ### Why are the changes needed? - A watermark on the stored side alone cannot prove that an opposite-side match will never arrive. Such outer and semi plans were accepted and could keep unmatched state indefinitely. - When the event-time keys sit at different equality-key ordinals, using one ordinal for both sides can discard a future match and emit a premature outer null row. One input's watermark also cannot bound its own state against future input from the other side. - Reading a null selected window as a struct crashes V4, and indexing a null key under another timestamp can remove it or emit an outer row too early. ### Does this PR introduce _any_ user-facing change? Yes. - Outer and semi plans without the required watermark direction fail analysis, with the missing direction and migration guidance in the error. Valid equality and range plans remain supported. - Valid matches are preserved and premature unmatched output is prevented in V2, V3 and V4. - Older V4 checkpoints whose selected equality key can be null are rejected with `STREAMING_JOIN_CHECKPOINT_INCOMPATIBLE`. ### How was this patch tested? All commands below passed on this branch, rebased on Apache Spark master: 805 tests, 0 failures. ```sh build/sbt 'catalyst/testOnly *StreamingJoinHelperSuite *UnsupportedOperationsSuite' # 296 build/sbt 'sql/testOnly *StreamingJoinWatermarkAdmissionSuite *StreamingJoinEqualityOutputWatermarkSuite *StreamingJoinOutputWatermarkSuite *StreamingJoinEqualityWatermarkSuite *StreamingJoinRangeEvictionSuite *StreamingSymmetricHashJoinHelperSuite *MultiStatefulOperatorsSuite *OffsetSeqLogSuite *SymmetricHashJoinStateManagerSuite *SymmetricHashJoinStateManagerEventTimeInKeySuite' # 190 build/sbt 'sql/testOnly *StreamingJoinCheckpointCompatibilitySuite *StreamingJoinRangeEvictionCheckpointSuite' # 223 build/sbt 'sql/testOnly *StreamingInnerJoin*Suite -- -z "matching scan on event time"' # 90 build/sbt 'sql/testOnly *StreamingFullOuterJoinV4Suite -- -z "null" -z "ordinal"' # 6 ``` Scalastyle for catalyst and sql, main and test sources: 0 errors, 0 warnings. The new tests failed before their fixes: - The admission tests started the query instead of throwing `AnalysisException`. - The V4 null-window tests crashed in both outer-join orientations and both changelog modes. - Six shifted-key analyzer cases were rejected, and all V2/V3/V4 runs of the shifted equality query failed analysis. - The old V4 `window()` checkpoint was rejected. - For the truncated key, the helper returned a bound, the analyzer admitted the left outer join, and the V2/V3/V4 runs lost the match. - The one-day shift tests failed the same three ways in America/Los_Angeles across the spring-forward change; the UTC controls passed. Shifts of -1 day and -36 hours across the fall-back change are covered as well. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) and 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]
