HeartSaVioR commented on code in PR #60669:
URL: https://github.com/apache/spark/pull/60669#discussion_r4621639469
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -362,6 +364,24 @@ case class StreamingSymmetricHashJoinExec(
}
protected override def doExecute(): RDD[InternalRow] = {
+ // Older versions order the V4 state of an input by its event time, so
their checkpoints
+ // cannot evict that state by another column.
+ if (stateFormatVersion == 4 &&
+ conf.getConf(SQLConf.STREAMING_JOIN_STATE_V4_INDEX_VERSION) == 0) {
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; see the reply there. I did not extend that check to inputs
without a watermark here: that case behaves as on master, and this PR does not
cause it.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -117,6 +117,27 @@ object StreamingJoinHelper extends PredicateHelper with
Logging {
allStateWatermarks.reduceOption((x, y) => Math.min(x, y))
}
+ /**
+ * Get the column that evicts the state of an input, with its state value
watermark. That is the
+ * event time if the input has one and the condition bounds it, and
otherwise the first other
+ * TIMESTAMP column in input order that the condition bounds. Each column is
solved on its own,
+ * so the cutoff applies to the column that the condition bounds.
+ */
+ def getStateValueWatermarkColumn(
+ inputAttributes: Seq[Attribute],
+ attributesWithEventWatermark: AttributeSet,
+ joinCondition: Option[Expression],
+ eventWatermark: Option[Long]): Option[(Attribute, Long)] = {
+ val eventTime = inputAttributes.find(_.metadata.contains(delayKey))
+ val candidates = eventTime.toSeq ++ inputAttributes.filter { a =>
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; see the reply there.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -722,6 +744,16 @@ case class StreamingSymmetricHashJoinExec(
private[this] val allowMultipleStatefulOperators: Boolean =
conf.getConf(SQLConf.STATEFUL_OPERATOR_ALLOW_MULTIPLE)
+ // The join condition bounds the column that the value predicate tests, so
a row with a NULL
+ // in it can never match, and the predicate never evicts it. The legacy
mode tests the event
+ // time even when the condition bounds another column.
+ private[this] val isEvictionColumnNull: UnsafeRow => Boolean =
stateWatermarkPredicate match {
+ case Some(JoinStateValueWatermarkPredicate(LessThanOrEqual(column, _),
_, _))
+ if allowMultipleStatefulOperators =>
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; see the reply there.
##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,32 @@ Please refer [Migration Guide: SQL, Datasets and
DataFrame](../sql-migration-gui
## Upgrading from Structured Streaming 4.3 to 4.4
+- Since Spark 4.4, a stream-stream join whose condition bounds an input with
its own watermark
+ only through another TIMESTAMP column, for example `rightTime BETWEEN
leftTime AND expiry`,
+ evicts the state of that input by the bounded column instead of its event
time. Earlier versions
+ could emit outer join rows too early and lose matches. An outer or left semi
join whose only such
+ bound is on a column that is not TIMESTAMP, such as a DATE column cast to
TIMESTAMP, now fails
+ analysis. Such a join with state format version 4 cannot restart from a
checkpoint of an earlier
+ version; start it with a new checkpoint. Rows that an earlier version
evicted are not restored.
+ With `spark.sql.streaming.statefulOperator.allowMultiple` set to false,
joins keep the earlier
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.
No longer applies: #60667's analysis rule is reverted, so a legacy-mode join
of this shape passes analysis as on master, and the sentence holds. Master's
early eviction for such cast-bounded inputs predates this stack and is
[SPARK-62044](https://issues.apache.org/jira/browse/SPARK-62044).
##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,32 @@ Please refer [Migration Guide: SQL, Datasets and
DataFrame](../sql-migration-gui
## Upgrading from Structured Streaming 4.3 to 4.4
+- Since Spark 4.4, a stream-stream join whose condition bounds an input with
its own watermark
+ only through another TIMESTAMP column, for example `rightTime BETWEEN
leftTime AND expiry`,
+ evicts the state of that input by the bounded column instead of its event
time. Earlier versions
+ could emit outer join rows too early and lose matches. An outer or left semi
join whose only such
+ bound is on a column that is not TIMESTAMP, such as a DATE column cast to
TIMESTAMP, now fails
+ analysis. Such a join with state format version 4 cannot restart from a
checkpoint of an earlier
+ version; start it with a new checkpoint. Rows that an earlier version
evicted are not restored.
+ With `spark.sql.streaming.statefulOperator.allowMultiple` set to false,
joins keep the earlier
+ behavior.
+
+- Since Spark 4.4, a range condition of a stream-stream join bounds the state
of one input only
+ if the other input's watermarked column appears in it with a positive sign,
for example
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.
This entry belongs to #60664, which already rewrote it in its latest commit.
--
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]