HeartSaVioR commented on code in PR #60667:
URL: https://github.com/apache/spark/pull/60667#discussion_r4624664011
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinHelper.scala:
##########
@@ -262,27 +262,44 @@ object StreamingSymmetricHashJoinHelper extends Logging {
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 =>
- StreamingJoinHelper.getStateValueWatermark(
- attributesToFindStateWatermarkFor =
AttributeSet(oneSideInputAttributes),
- attributesWithEventWatermark =
AttributeSet(otherSideInputAttributes),
- condition,
- eventTimeWatermarkForLateEvents).filter(_ <= lateWatermark)
+ val eventTime =
oneSideInputAttributes.find(_.metadata.contains(delayKey))
+ // The legacy mode with a single global watermark keeps applying a
cutoff on any column of
+ // this input to the event time. So does the default mode when the
condition bounds no
+ // TIMESTAMP column, such as through a DATE column cast to TIMESTAMP
only.
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 a TODO naming
[SPARK-62044](https://issues.apache.org/jira/browse/SPARK-62044) above the
fallback.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -4399,6 +4399,21 @@ object SQLConf {
.checkValue(v => Set(1, 2, 3, 4).contains(v), "Valid versions are 1, 2,
3, and 4")
.createWithDefault(2)
+ val STREAMING_JOIN_STATE_V4_INDEX_VERSION =
+ buildConf("spark.sql.streaming.join.stateFormatV4.indexVersion")
+ .internal()
+ .withBindingPolicy(ConfigBindingPolicy.NOT_APPLICABLE)
+ .doc("How state format version 4 of stream-stream joins orders the state
of an input that " +
+ "it evicts by a range condition. 0: by the event time of the input, as
in 4.3 and " +
+ "earlier and with spark.sql.streaming.statefulOperator.allowMultiple
set to false. 1: by " +
+ "the column that the condition bounds. A streaming query keeps the
version recorded in " +
+ "its checkpoint, and one restarted from a checkpoint without it uses
0. With 0, a join " +
+ "whose condition does not bound the event time of such an input fails
to restart.")
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.
Reworded: version 1 orders by the column the default mode evicts the input
by (the event time for an input bounded only through a cast column), and
version 0 fails only when the default mode evicts such an input by another
TIMESTAMP column.
##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,18 @@ 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
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.
Reworded the entry to name the joins by what limits how long a row can
match, and added a sentence on rows whose eviction column is NULL, both
arriving and already in a state format 1-3 checkpoint. The entry is now in a
new 4.4-to-4.5 section, since this targets Spark 4.5.
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -362,6 +364,32 @@ 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.
+ 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 =>
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 both: a legacy-mode restart of a version-1 time-interval join that
works across the restart, and a right outer join evicted by `expiry` whose
legacy-mode restart fails for the right input.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -117,6 +117,29 @@ 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 own watermark,
with its state value
+ * watermark. That is the event time if 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 references =
joinCondition.map(_.references).getOrElse(AttributeSet.empty)
+ 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.
Added an assertion with two bounding TIMESTAMP columns in both input orders;
the first one in input order wins.
--
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]