HeartSaVioR commented on code in PR #60280:
URL: https://github.com/apache/spark/pull/60280#discussion_r4546999839
##########
common/utils/src/main/resources/error/error-conditions.json:
##########
@@ -8165,6 +8165,20 @@
],
"sqlState" : "55019"
},
+ "STREAMING_JOIN_CHECKPOINT_INCOMPATIBLE" : {
+ "message" : [
+ "Cannot reuse the checkpoint for the stream-stream join with condition
<joinCondition>. Watermarked columns: left [<leftWatermarkColumns>], right
[<rightWatermarkColumns>].",
+ "This Spark version changes how watermarks determine which rows can
still match. Spark cannot verify that rows saved by the previous version can be
reused safely for this join. Start the query with a new checkpoint and replay
the required input, accounting for previously written results to avoid
duplicates and correct any missing or incorrect output."
+ ],
+ "sqlState" : "0A000"
+ },
+ "STREAMING_JOIN_UNBOUNDED_DOWNSTREAM_EVENT_TIME" : {
+ "message" : [
+ "The append-mode aggregation after a stream-stream join uses the event
time <eventTime> of the join's <side> input, but the join cannot bound the
state of that input, so it holds back its output watermark and the aggregation
would never emit results.",
Review Comment:
> [!NOTE]
> **DISCLAIMER:** This comment was written by an LLM: Claude Sonnet 5.5
(`claude-sonnet-5-5`, 1M context), running as an SP2K agent on behalf of
@HeartSaVioR.
Fixed in
[738ebe585c9](https://github.com/apache/spark/pull/60280/commits/738ebe585c98779d084c4c661c1b27a71ecbc8de).
The error now says the join has no bound on that event time for the input's
state, not that it cannot bound the state. It also names what provides a bound:
an equality with an exact shift (an interval under one day, or `timestampadd`
in hours, minutes or seconds), or a range condition used in place of a shifted
equality. The Left Outer and Right Outer rows of the join support table and the
migration guide say the same.
<!-- sp2k-review3 reply 4537719990 -->
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -35,18 +35,253 @@ import org.apache.spark.unsafe.types.CalendarInterval
object StreamingJoinHelper extends PredicateHelper with Logging {
/**
- * Check the provided logical plan to see if its join keys contain a
watermark attribute.
- *
- * Will return false if the plan is not an equijoin.
- * @param plan the logical plan to check
+ * Find the equality key filtered by this input's watermark. Its ordinal can
be used to
+ * evict the opposite input's state, whose equality keys have the same
ordering.
+ * For leftTime = rightTime, a watermark on rightTime bounds leftTime even
when leftTime
+ * has no watermark. It does not bound right-side state without a watermark
on leftTime.
+ * A key computed from the event time by adding constant intervals, such as
+ * leftTime = rightTime + INTERVAL 10 SECONDS or leftTime =
timestampadd(HOUR, 1, rightTime),
+ * is bounded too if the solver can count the intervals exactly or they
never move a time
+ * backward; see [[getStateKeyWatermark]]. The result does not depend on the
session time zone,
+ * so neither does the V4 state layout.
+ */
+ def getStateKeyWatermarkOrdinal(
+ keys: Seq[Expression],
+ inputAttributes: Seq[Attribute]): Option[Int] = {
+ getEventTimeKeyOrdinal(keys, inputAttributes).orElse {
+ keys.indices.find(getStateKeyWatermark(keys, inputAttributes, _,
Some(0L)).isDefined)
+ }
+ }
+
+ /** Find the equality key that is this input's event-time column itself. */
+ def getEventTimeKeyOrdinal(
+ keys: Seq[Expression],
+ inputAttributes: Seq[Attribute]): Option[Int] = {
+ // When multiple stateful operators are disabled, late filtering uses the
first event-time
+ // column. Otherwise, execution rejects multiple distinct event-time
columns.
+ inputAttributes.find(_.metadata.contains(delayKey)).flatMap { eventTime =>
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. You are right that this is a regression from the base branch, and
that it stays at the top of the stack: s3 to s7 do not change how an equality
key bounds state. We still keep the fix out of this stack. SPARK-61448 tracks
it. Our reasons:
- **The case is narrow.**
`spark.sql.streaming.statefulOperator.allowMultiple` is an internal conf and is
true by default. The regression needs it set to false, an input that keeps both
`t` and `window(t)` with `t` first, and a join on the window.
- **No existing query of this shape keeps its checkpoint.** The restart
check from SPARK-61344 accepts only inputs with one watermarked column, as your
Exclusions note says. So every affected user starts a new checkpoint. At that
point the workaround costs nothing: put the window before `t`, or drop `t`. The
join then evicts by window end, exactly as the base branch did.
- **No result is wrong.** Outer and left semi joins fail at analysis, and
the error names both columns and the fix. An inner join keeps more state than
it needs, but it returns the right rows.
- **The fix is not small, and a mistake in it gives wrong results.** The
admission check reads the analyzed plan, but eviction runs on the physical
plan, after the optimizer has collapsed the projections that `window()` and
`withColumn` add. So the decision must be made once on the logical join and
carried to `StreamingSymmetricHashJoinExec`, its state predicates and the V4
lookup ordinal. If the plan walk accepts a key that is not built from the
late-filtered column, the join drops rows that can still match, with no error.
Today's rule can only keep too much state.
We would rather build that walk on its own, on top of the stack, with its
own tests. Until SPARK-61448 lands, the migration guide note and the error hint
stay.
<!-- sp2k-review3 reply 4537719964 -->
--
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]