HeartSaVioR commented on code in PR #60307:
URL: https://github.com/apache/spark/pull/60307#discussion_r4530847116
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -910,6 +912,8 @@ case class StreamingSymmetricHashJoinExec(
!stateKeyWatermarkPredicateFunc(key) &&
!stateValueWatermarkPredicateFunc(thisRow)
isNotEvictingInThisBatch ||
+ // if the left input of this batch still has to probe the input
+ joinType == LeftSemi ||
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Thanks. The cost is real: a left semi join now writes, and removes in the
same batch, every right row that passes late filtering and that the batch
evicts, including rows that no left row of the batch can match, such as most
in-order rows of `rightTime BETWEEN leftTime + INTERVAL 1 MINUTE AND leftTime +
INTERVAL 1 HOUR`. We are keeping it, because the proposed narrowing can drop a
match on master.
Take `leftKey = rightKey AND rightExpiry >= leftTime + INTERVAL 30 SECONDS
AND leftTime >= rightTime - INTERVAL 1 HOUR`, with 0-second watermarks on
`leftTime` and `rightTime`. In a batch whose late-events watermark is 100 s and
whose eviction watermark is 150 s, left (1, 120) matches right (1, rightTime
110 s, rightExpiry 1000 s). The base branch emits nothing, and this fix emits
(1, 120). At the late-events watermark, `getStateWatermarkPredicates` gives the
right cutoff `rightTime <= 129.999 s`, because it applies the bound on
`rightExpiry` to `rightTime`. So the narrowing would skip that right row and
drop the match again.
A sound narrowing needs a cutoff for each right column (SPARK-61344) and an
exact cutoff solver, which today counts a day as 24 hours and reads truncating
casts as exact (SPARK-61381). Until then, storing every evicted right row is
the change that cannot drop a match, and it backports cleanly. In
[ce03e8d2703](https://github.com/apache/spark/pull/60307/commits/ce03e8d2703a8f7f6469ee143b71ede85e43f560),
the comment at this check says so, with a TODO for both tickets, and a new
test pins the match above.
<!-- sp2k-review2 reply 4529610402 -->
##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingJoinSuite.scala:
##########
@@ -2425,6 +2425,45 @@ abstract class StreamingLeftSemiJoinBase extends
StreamingJoinSuite {
}
}
+ // A left semi join processes the right input before the left input. A right
row at or below
+ // its eviction cutoff passes late filtering when it is above the
late-events watermark, and
+ // the left rows of the same batch must still find it. Each case runs a
batch whose
+ // late-events watermark is 100 seconds and whose eviction watermark is
`watermark` seconds.
+ // (name, condition, left time, right time, watermark, state rows after the
second batch and
+ // after the third)
+ for ((name, condition, leftTime, rightTime, watermark, rowsBefore,
rowsAfter) <- Seq(
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Opus 5.5
(`claude-opus-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Fixed in
[ce03e8d2703](https://github.com/apache/spark/pull/60307/commits/ce03e8d2703a8f7f6469ee143b71ede85e43f560).
The same-batch tests now include `leftTime BETWEEN rightTime - INTERVAL 10
SECONDS AND rightTime + INTERVAL 10 SECONDS`, with left (1, 125) and right (1,
130) in the batch whose watermarks are 100 s and 150 s. The test checks the
output and the state rows (4 after the second batch, 2 after the third) in V2,
V3 and V4. It fails on the base branch, which emits nothing in that batch.
<!-- sp2k-review2 reply 4529610417 -->
--
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]