HeartSaVioR commented on code in PR #60669:
URL: https://github.com/apache/spark/pull/60669#discussion_r4662098721
##########
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 =>
+ joinInputWithoutStateCutoff(j).foreach { side =>
+ throwError("Detected pattern of possible 'correctness' issue:
the state of the " +
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.
The error comes from the
[SPARK-62001](https://issues.apache.org/jira/browse/SPARK-62001) check
(#60713), which keeps the `_LEGACY_ERROR_TEMP_3102` helper of the
chained-operator check it extends; moving the file's checks to named conditions
is better done for all of them at once.
##########
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 =>
+ joinInputWithoutStateCutoff(j).foreach { side =>
+ throwError("Detected pattern of possible 'correctness' issue:
the state of the " +
+ s"$side input of a stream-stream join has no cutoff, so the
join can emit its " +
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: the message now says that the state of that input has no
cutoff on its event time, and names a range condition on the event time as the
remedy.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -66,13 +66,17 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
* @param attributesWithEventWatermark attributes of the other side which
has a watermark column
* @param joinCondition join condition
* @param eventWatermark watermark defined on the input event
data
+ * @param risingCutoffsOnly whether only conjuncts whose cutoff
rises with the
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: the doc names the cases that keep the earlier minimum.
##########
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 =>
+ joinInputWithoutStateCutoff(j).foreach { side =>
+ throwError("Detected pattern of possible 'correctness' issue:
the state of the " +
+ s"$side input of a stream-stream join has no cutoff, so the
join can emit its " +
+ "old rows below its output watermark, and a later stateful
operator drops them " +
+ "as late. Add a watermark in the join keys or a range
condition that bounds " +
+ "that input by the other input's watermark, or set " +
+
"`spark.sql.streaming.statefulOperator.checkCorrectness.enabled` to false.")(j)
+ }
+ case _ =>
+ }
+ }
+ }
+ } catch {
+ case e: AnalysisException if !failWhenDetected =>
+ logWarning(log"${MDC(ANALYSIS_ERROR, e.message)};\n${MDC(QUERY_PLAN,
plan)}", e)
+ }
+ }
+
+ // An input of a stream-stream join with an event time but no state cutoff,
as eviction derives
+ // it: no watermark in the join keys, and no range condition that bounds the
input by the
+ // watermark of the other input. With allowMultiple, an input that eviction
picks another column
+ // for counts too, since its state keeps rows of any event time. A left semi
join only emits
+ // left rows.
+ private def joinInputWithoutStateCutoff(join: Join): Option[String] = join
match {
+ case Join(left, right, joinType, condition, _) if left.isStreaming &&
right.isStreaming &&
+ !StreamingJoinHelper.isWatermarkInJoinKeys(join) =>
+ Seq(("left", left, right), ("right", right, left)).take(if (joinType ==
LeftSemi) 1 else 2)
+ .collectFirst {
+ case (side, input, other) if input.output.exists(hasEventTimeCol) &&
(
+ StreamingJoinHelper.getStateValueWatermark(
+ input.outputSet, other.outputSet, condition,
Some(1000000)).isEmpty ||
+ SQLConf.get.getConf(SQLConf.STATEFUL_OPERATOR_ALLOW_MULTIPLE) &&
+ StreamingJoinHelper.getStateValueWatermarkColumn(input.output,
other.outputSet,
+ condition, Some(1000000)).exists { case (column, _) =>
!hasEventTimeCol(column) }
+ ) => side
+ }
+ case _ => None
+ }
+
+ // A stateful operator that drops the input rows below its watermark for
late rows. Its
+ // physical operator filters by an event-time column of its input, so it
needs one.
+ private def dropsLateRows(p: LogicalPlan): Boolean = p.isStreaming &&
+ p.children.exists(_.output.exists(hasEventTimeCol)) && (p match {
+ case _: Aggregate | _: Distinct | _: Deduplicate | _:
DeduplicateWithinWatermark => true
+ case Join(left, right, _, _, _) => left.isStreaming && right.isStreaming
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.
These branches are #60713's; its update adds tests for them.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -362,6 +364,45 @@ case class StreamingSymmetricHashJoinExec(
}
protected override def doExecute(): RDD[InternalRow] = {
+ // Older versions and the legacy mode order the V4 state of an input by
its event time (index
+ // version 0), so their checkpoints cannot evict that state by another
column. Index version 1
+ // orders it by the column that the default mode picks, which the legacy
mode cannot evict.
+ // They keep the rows of an input without an event time out of the index.
Such rows are never
+ // evicted, which only an outer join that emits the unmatched rows of that
input cannot accept,
+ // so it fails with a checkpoint written by an earlier version or started
in the legacy mode.
+ // TODO: [SPARK-62075] A legacy-mode run of a version 1 checkpoint is not
checked for an input
+ // without an event time. That input has no predicate in the legacy mode,
so the rows of the
+ // run get no index entry, and the default mode never evicts them
afterwards.
+ val indexVersion =
conf.getConf(SQLConf.STREAMING_JOIN_STATE_V4_INDEX_VERSION)
+ if (stateFormatVersion == 4 && (indexVersion == 0 ||
!allowMultipleStatefulOperators)) {
+ Seq((LeftSide, stateWatermarkPredicates.left, left.output, right.output),
+ (RightSide, stateWatermarkPredicates.right, right.output,
left.output)).foreach {
+ case (side, predicate, attributes, otherAttributes) =>
+ val eventTime = WatermarkSupport.findEventTimeColumnIndex(
+ attributes, allowMultipleEventTimeColumns = false)
+ val column = if (indexVersion == 0) {
+ stateValueWatermarkColumnOrdinal(predicate, attributes)
+ } else {
+ predicate.collect { case _: JoinStateValueWatermarkPredicate =>
+ StreamingJoinHelper.getStateValueWatermarkColumn(attributes,
+ AttributeSet(otherAttributes), condition.full, Some(0L))
+ }.flatten.map { case (c, _) =>
attributes.indexWhere(_.semanticEquals(c)) }
+ }
+ val emitsUnmatchedRows = joinType match {
+ case LeftOuter => side == LeftSide
+ case RightOuter => side == RightSide
+ case FullOuter => true
+ case _ => false
+ }
+ column.filterNot(eventTime.contains)
+ .filter(_ => eventTime.isDefined || emitsUnmatchedRows).foreach {
i =>
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.
Added an inner join restart from an index-version-0 checkpoint, which fails
for the left input and `expiry`.
--
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]