HeartSaVioR commented on code in PR #60379:
URL: https://github.com/apache/spark/pull/60379#discussion_r4607322474


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -230,6 +233,53 @@ case class StreamingSymmetricHashJoinExec(
 
   private val useVirtualColumnFamilies = stateFormatVersion >= 3
 
+  // Only the V4 state manager reads these ordinals. They depend only on plan 
fields, so
+  // doExecute computes them once on the driver instead of in every task.
+  private lazy val stateKeyOrdinalsForLookup: (Option[Int], Option[Int]) =
+    if (stateFormatVersion >= 4) {
+      (getStateKeyOrdinalForLookup(
+        left.output, leftKeys, right.output, rightKeys, 
stateWatermarkPredicates.left),
+        getStateKeyOrdinalForLookup(
+          right.output, rightKeys, left.output, leftKeys, 
stateWatermarkPredicates.right))
+    } else {
+      (None, None)
+    }
+
+  /**
+   * The window of the other side's state that a row of `joinSide` reads in 
V4, or None to read
+   * every row for the key. V4 orders a side's state by a timestamp, unless 
the side has a key
+   * ordinal (see getStateKeyOrdinalForLookup), whose lookups read the key's 
exact timestamp.
+   * That timestamp is the column the side's value-eviction predicate 
constrains, or its event
+   * time if it has no such predicate. The window bounds that column with the 
join condition
+   * evaluated on the row; see [[MatchingScanWindow]]. For rightTime BETWEEN 
leftTime AND expiry,
+   * the left side evicts on expiry: a left row reads right rows with 
rightTime in
+   * [leftTime, expiry], and a right row reads left rows with expiry at or 
above rightTime.
+   */
+  private[sql] def matchingScanWindow(joinSide: JoinSide): 
Option[MatchingScanWindow] = {
+    val (inputAttributes, otherAttributes, otherKeyOrdinal, otherPredicate) = 
joinSide match {
+      case LeftSide =>
+        (left.output, right.output, stateKeyOrdinalsForLookup._2, 
stateWatermarkPredicates.right)
+      case RightSide =>
+        (right.output, left.output, stateKeyOrdinalsForLookup._1, 
stateWatermarkPredicates.left)
+    }
+    if (stateFormatVersion < 4 || otherKeyOrdinal.isDefined) {
+      None
+    } else {
+      
SymmetricHashJoinStateManager.valueTimestampColumnOrdinal(otherAttributes,

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, agreed that the windows should not add a way to miss matches, so 
this PR now records the
   layout in 
[6b9149d6d6f](https://github.com/apache/spark/pull/60379/commits/6b9149d6d6f9e6aece79a7e6d6016ef959020d51).
 The join writes each side's V4 ordering (an equality-key ordinal, a value 
column's ordinal
   and type, or none) into `StreamingJoinOperatorProperties`, with a flag for a 
side that may hold rows
   stored under another ordering. Each batch compares the record of the 
previous batch with the
   current plan; a changed ordering sets the flag, and the flag is carried 
forward for the life of the
   checkpoint. A probe into a flagged side gets no window and reads every row 
of its key, as on the
   base branch. A checkpoint without the record counts as ordered by the 
current plan. The join's
   metadata of a batch is rewritten when the batch runs again, so the record 
follows the run that
   commits it. Exact key lookups and eviction still follow the current plan and 
stay with the separate
   checkpoint-format change; the guide now says so. Tests restart an inner join 
after adding a
   watermark on the left input, which moves the left ordering, and match left 
rows stored before the
   restart in that run and the next one, and check that a restart without a 
change keeps both windows.
   
   <!-- sp2k-review11 reply 4598997113 -->
   



-- 
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]

Reply via email to