HeartSaVioR commented on code in PR #60669:
URL: https://github.com/apache/spark/pull/60669#discussion_r4662097657
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -156,6 +156,73 @@ object UnsupportedOperationChecker extends Logging {
}
}
+ /**
+ * Checks, in append mode, for an operator that drops late rows after a
stream-stream join whose
+ * state of an input has no cutoff, as
[[checkStreamingQueryGlobalWatermarkLimit]] does for other
+ * operators. It takes the optimized plan, whose join conditions eviction
uses. A query from a
+ * checkpoint without `STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK` only
logs a warning.
+ */
+ def checkStreamStreamJoinOutputWatermark(plan: LogicalPlan, outputMode:
OutputMode): Unit = {
+ val failWhenDetected = SQLConf.get.statefulOperatorCorrectnessCheckEnabled
&&
+
SQLConf.get.getConf(SQLConf.STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK)
+ try {
+ plan.foreach { subPlan =>
+ // TODO: Update mode is not checked, although its aggregations also
drop late rows.
+ if (outputMode == InternalOutputModes.Append &&
dropsLateRows(subPlan)) {
+ subPlan.foreach {
+ case j: Join if j ne subPlan =>
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 #60713: the check now traces the event-time column that the later
operator filters by down to the join, through projections, filters, watermarks
and the expansion of a sliding window, and rejects only when it can come from
an input without a cutoff, or when the path has any other node. So `leftKey =
rightKey AND rightTime <= leftTime + INTERVAL 10 SECONDS` before a window on
`leftTime` runs.
#60713's round 5,
[e4ec72eccf8](https://github.com/apache/spark/pull/60713/commits/e4ec72eccf83367ee1a8d59de8182b7ed170e1ee),
fixes the two cases of the trace that were still open: an aggregation's trace
now starts from its grouping columns, so a window on one input's time that also
aggregates the other input's time runs, and the trace follows nodes that pass
their input's columns through unchanged, such as a repartition or a join with a
static table. This branch does not include that commit yet; if this review
raises those cases again, they are fixed in #60713.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -156,6 +156,73 @@ object UnsupportedOperationChecker extends Logging {
}
}
+ /**
+ * Checks, in append mode, for an operator that drops late rows after a
stream-stream join whose
+ * state of an input has no cutoff, as
[[checkStreamingQueryGlobalWatermarkLimit]] does for other
+ * operators. It takes the optimized plan, whose join conditions eviction
uses. A query from a
+ * checkpoint without `STATEFUL_OPERATOR_CHECK_JOIN_OUTPUT_WATERMARK` only
logs a warning.
+ */
+ def checkStreamStreamJoinOutputWatermark(plan: LogicalPlan, outputMode:
OutputMode): Unit = {
+ val failWhenDetected = SQLConf.get.statefulOperatorCorrectnessCheckEnabled
&&
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 #60667, which this PR is stacked on: a query restarted from a
checkpoint written before the check keeps the earlier eviction for an input
that would be evicted by another column, so the later operator receives what it
received before the upgrade. The same holds for an input without its own
watermark, which is then not evicted, as before.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -710,17 +753,44 @@ case class StreamingSymmetricHashJoinExec(
Predicate.create(Literal(false), Seq.empty).eval _ // false = do not
remove if no predicate
}
+ private[this] var updatedStateRowsCount = 0
+ private[this] var numRemovedFromOtherSideDuringJoinCount = 0
+ private[this] val allowMultipleStatefulOperators: Boolean =
+ conf.getConf(SQLConf.STATEFUL_OPERATOR_ALLOW_MULTIPLE)
+
+ // When the default mode picked the column that the value predicate tests
because the join
+ // condition bounds it, a row with a NULL in it can never match, and
`column <= cutoff` never
+ // holds for it. The legacy mode, and the default mode for an input
bounded only through a
+ // column cast to TIMESTAMP, test the event time, which the condition need
not bound.
+ private[this] val isEvictionColumnNull: UnsafeRow => Boolean =
stateWatermarkPredicate match {
+ case Some(JoinStateValueWatermarkPredicate(LessThanOrEqual(column, _),
_, _, true)) =>
+ Predicate.create(IsNull(column), inputAttributes).eval _
+ case _ => _ => false
+ }
+
+ // Such a row is not stored, but an earlier version or the legacy mode can
have stored one.
private[this] val stateValueWatermarkPredicateFunc =
stateWatermarkPredicate match {
- case Some(JoinStateValueWatermarkPredicate(expr, _, _)) =>
+ case Some(JoinStateValueWatermarkPredicate(expr @
LessThanOrEqual(column, _), _, _, true)) =>
+ Predicate.create(Or(expr, IsNull(column)), inputAttributes).eval _
+ case Some(JoinStateValueWatermarkPredicate(expr, _, _, _)) =>
Predicate.create(expr, inputAttributes).eval _
case _ =>
Predicate.create(Literal(false), Seq.empty).eval _ // false = do not
remove if no predicate
}
- private[this] var updatedStateRowsCount = 0
- private[this] var numRemovedFromOtherSideDuringJoinCount = 0
- private[this] val allowMultipleStatefulOperators: Boolean =
- conf.getConf(SQLConf.STATEFUL_OPERATOR_ALLOW_MULTIPLE)
+ // A left semi join processes its right input first, so this batch's left
rows can still match
+ // a right row that the completion check skips (SPARK-61380). Earlier
versions tested it against
+ // the cutoff on the event time solved over the whole input, which a
picked column can exceed.
+ private[this] val skipsEvictingRightRow: UnsafeRow => Boolean =
stateWatermarkPredicate match {
+ case Some(p: JoinStateValueWatermarkPredicate) if
p.conditionBoundsColumn &&
+ joinType == LeftSemi && joinSide == RightSide =>
+ val cutoff =
StreamingJoinHelper.getStateValueWatermark(AttributeSet(inputAttributes),
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 #60664, which this PR is stacked on: the left semi right-row skip
uses the earlier cutoff again, with negative-sign and constant-only conjuncts.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinHelper.scala:
##########
@@ -261,28 +266,65 @@ object StreamingSymmetricHashJoinHelper extends Logging {
eventTimeWatermarkForEviction.get,
prevStateKeyWatermark)
}
- } else if (isWatermarkDefinedOnInput) { // case 2 in the
StreamingSymmetricHashJoinExec docs
- val stateValueWatermark = StreamingJoinHelper.getStateValueWatermark(
- attributesToFindStateWatermarkFor =
AttributeSet(oneSideInputAttributes),
- attributesWithEventWatermark =
AttributeSet(otherSideInputAttributes),
- condition,
- eventTimeWatermarkForEviction)
- // A row can pass late-input filtering but already be eligible for
eviction in this batch.
- // When the previous join-derived state cutoff is ahead of the
late-input watermark, a new
- // row can fall at or below that cutoff. V4 must scan from the
beginning to find such rows.
- val prevStateValueWatermark = eventTimeWatermarkForLateEvents.flatMap
{ lateWatermark =>
+ } else if (isWatermarkDefinedOnInput || !useFirstEventTimeColumn) {
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: an input without its own watermark now gets no cutoff from a conjunct
through a cast that can round or drop digits, on either input's column, so your
examples return the match as master does, while exact bounds still evict. New
tests cover `CAST(lt AS LONG)` and `CAST(lt AS DOUBLE)` against `CAST(rt AS
LONG) - 5`, for inner and left outer joins on state formats 2 and 4.
--
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]