spark-test commented on code in PR #60379:
URL: https://github.com/apache/spark/pull/60379#discussion_r4598997113


##########
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:
   Thanks for the detailed reply. One point on the premise: in the example 
above, neither side's state is evicted in either run, so on master each right 
row reads every stored left row of its key and every match is emitted. With 
this PR, the window alone makes the later right rows skip the left rows stored 
before the restart; it does not add to a failure that already existed. On 
master, the only probes that relied on the layout derived from the current plan 
were V4's exact key lookups and its constant-offset event-time window, and 
every other probe read all stored rows of its key. In the q9 case you describe, 
eviction is exposed too, so a flag that only turns off windows would not cover 
it. What remains open is whether this PR records the layout or leaves it, with 
the guide note, to the separate change.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4582134210","thread_id":"inline:4582134210","verdict_sha256":"d5223a5164ae4c6dd514cb8b543b531797d7f70758bc2b844f117aa9cac7789e"}
 -->



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