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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinHelper.scala:
##########
@@ -262,27 +262,34 @@ 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 inputAttributeWithWatermark = 
oneSideInputAttributes.find(_.metadata.contains(delayKey))
-        val expr = watermarkExpression(inputAttributeWithWatermark, 
stateValueWatermark)
-        expr.map { e =>
-          // watermarkExpression only provides the expression when 
eventTimeWatermarkForEviction
-          // is defined
-          JoinStateValueWatermarkPredicate(e, stateValueWatermark.get, 
prevStateValueWatermark)
+        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.
+        def solve(watermark: Option[Long]): Option[(Attribute, Long)] =
+          if (useFirstEventTimeColumn) {
+            StreamingJoinHelper.getStateValueWatermark(
+              attributesToFindStateWatermarkFor = 
AttributeSet(oneSideInputAttributes),
+              attributesWithEventWatermark = 
AttributeSet(otherSideInputAttributes),
+              condition,
+              watermark).map(eventTime.get -> _)
+          } else {
+            
StreamingJoinHelper.getStateValueWatermarkColumn(oneSideInputAttributes,

Review Comment:
   Thanks for reproducing it. Leaving the output watermark itself to 
SPARK-62001 is fine, but until it lands a query like this should not start and 
lose rows silently: the window aggregation now drops the unmatched row for key 
2, which master emitted and counted, as well as the match at 460 s that the 
change now finds. Please treat such a join like the other operators that can 
emit rows older than the watermark: in the default mode, when an input with its 
own watermark is evicted by a column other than its event time, a stateful 
operator after the join should fail analysis with the existing correctness 
error, or start with that warning when 
spark.sql.streaming.statefulOperator.checkCorrectness.enabled is false. The 
migration note can then say that such a query fails at start instead of saying 
that the operator can drop the rows, and the tests should cover a rejected 
query and joins that still pass, such as a time-interval join bounded through 
both event times and a join bounded only 
 through a column cast to TIMESTAMP.
   
   <!-- SPARK_DEV_REVIEW_REPLY 
{"feedback_id":"inline:4615752059","thread_id":"inline:4615752059","verdict_sha256":"644f3b1e2a3e634f21120f1fc2761b5e1c004301043ba2c09212b7cdec0ef27d"}
 -->



##########
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.
+        def solve(watermark: Option[Long]): Option[(Attribute, Long)] = {
+          def wholeInput = eventTime.flatMap { e =>
+            StreamingJoinHelper.getStateValueWatermark(
+              attributesToFindStateWatermarkFor = 
AttributeSet(oneSideInputAttributes),
+              attributesWithEventWatermark = 
AttributeSet(otherSideInputAttributes),
+              condition,
+              watermark).map(e -> _)
+          }
+          if (useFirstEventTimeColumn) {
+            wholeInput
+          } else {
+            
StreamingJoinHelper.getStateValueWatermarkColumn(oneSideInputAttributes,
+              AttributeSet(otherSideInputAttributes), condition, 
watermark).orElse(wholeInput)

Review Comment:
   **Non-blocking (P2):** No test reaches this fallback: the catalyst test 
stops at getStateValueWatermarkColumn returning None for `CAST(leftNtz AS 
TIMESTAMP) > rightTime`, and every join test bounds only TIMESTAMP columns. 
Removing `.orElse(wholeInput)` would bring back what the previous review raised 
for full outer joins, an input that is never evicted and whose unmatched rows 
are never emitted, without any test failing, and the NULL-rule problem on this 
path went unnoticed for the same reason.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60667#discussion_r4615752086).
   
   See **Shared repair plan 1** in the review body.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -710,18 +740,30 @@ case class StreamingSymmetricHashJoinExec(
         Predicate.create(Literal(false), Seq.empty).eval _ // false = do not 
remove if no predicate
     }
 
+    private[this] var updatedStateRowsCount = 0
+    private[this] var numRemovedFromOtherSideDuringJoinCount = 0
+    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 `column <= cutoff` never holds for 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:
   **Blocking (P1):** This guard applies the NULL screen whenever the default 
mode builds a `column <= cutoff` predicate, but the premise in the comment 
above, that the condition bounds that column, does not hold on the new 
fallback. For `leftKey = rightKey AND CAST(leftDate AS TIMESTAMP) >= rightTime` 
the fallback tests leftTime, which the condition does not reference, so by the 
review's reading of the code a left row (1, leftTime NULL, leftDate 1970-01-02) 
passes late filtering and then skips the join and the state: an inner join 
returns nothing instead of its match with a stored right row (1, 100 s), and a 
left outer join emits `(1, null)` instead. On state formats 1 to 3 the same 
test also evicts such rows that an earlier version or the legacy mode stored. 
The base branch joined and kept these rows, and no IsNotNull filter on leftTime 
is inferred, because the condition does not reference it.
   
   This extends existing discussions 
[1](https://github.com/apache/spark/pull/60667#issuecomment-6993038562), 
[2](https://github.com/apache/spark/pull/60667#discussion_r4615752076).
   
   See **Shared repair plan 1** in the review body.



##########
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:
   **Nit (P3):** This comment presents the fallback as the default mode's rule, 
but for an input bounded only through a DATE, TIMESTAMP_NTZ, or numeric column 
cast to TIMESTAMP it keeps the base branch's eviction by the event time with 
the cast column's cutoff, which still emits outer rows too early and loses 
matches. The PR description defers that to SPARK-62044, but no file in the 
change names it, so a reader can take the fallback for intended behavior or 
copy it as correct; a TODO naming SPARK-62044 here would mark the gap.
   
   **Verification:**
   - **Inspection:** The comment above the whole-input fallback in 
getStateWatermarkPredicates carries a TODO naming SPARK-62044 that says inputs 
bounded only through a DATE, TIMESTAMP_NTZ, or numeric column cast to TIMESTAMP 
keep the early eviction by the event time.



##########
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.
+        def solve(watermark: Option[Long]): Option[(Attribute, Long)] = {
+          def wholeInput = eventTime.flatMap { e =>
+            StreamingJoinHelper.getStateValueWatermark(
+              attributesToFindStateWatermarkFor = 
AttributeSet(oneSideInputAttributes),
+              attributesWithEventWatermark = 
AttributeSet(otherSideInputAttributes),
+              condition,
+              watermark).map(e -> _)
+          }
+          if (useFirstEventTimeColumn) {
+            wholeInput
+          } else {
+            
StreamingJoinHelper.getStateValueWatermarkColumn(oneSideInputAttributes,
+              AttributeSet(otherSideInputAttributes), condition, 
watermark).orElse(wholeInput)
+          }
         }
-        val inputAttributeWithWatermark = 
oneSideInputAttributes.find(_.metadata.contains(delayKey))
-        val expr = watermarkExpression(inputAttributeWithWatermark, 
stateValueWatermark)
-        expr.map { e =>
-          // watermarkExpression only provides the expression when 
eventTimeWatermarkForEviction
-          // is defined
-          JoinStateValueWatermarkPredicate(e, stateValueWatermark.get, 
prevStateValueWatermark)
+        solve(eventTimeWatermarkForEviction).flatMap { case (column, 
stateValueWatermark) =>
+          // 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. Late-input filtering bounds only the 
event time, so a
+          // cutoff on another column always scans from the beginning. The 
bound is solved over
+          // the whole input, as earlier versions and the legacy mode evicted 
only up to it.
+          val prevStateValueWatermark = eventTimeWatermarkForLateEvents.filter 
{ _ =>
+            eventTime.exists(_.semanticEquals(column))
+          }.flatMap { lateWatermark =>
+            StreamingJoinHelper.getStateValueWatermark(
+              attributesToFindStateWatermarkFor = 
AttributeSet(oneSideInputAttributes),

Review Comment:
   **Non-blocking (P2):** This start is the whole-input cutoff at the 
late-events watermark, which a restart needs, but within a run the previous 
batch already evicted up to the event time's own cutoff at that watermark. For 
`leftTime >= rightTime - INTERVAL 10 SECONDS AND expiry >= rightTime - INTERVAL 
100 SECONDS`, every batch after the first therefore scans the tombstones of the 
rows evicted during the last 90 s of watermark progress before it reaches live 
entries. The base branch did no such work for this input, whose results it 
already got right; the size depends on RocksDB compaction and has not been 
measured.
   
   This extends existing discussions 
[1](https://github.com/apache/spark/pull/60667#issuecomment-6993038562), 
[2](https://github.com/apache/spark/pull/60667#discussion_r4615752153).
   
   **Recommended change:** After the first batch of a run, start the state 
format 4 eviction scan of an input that the default mode evicts by its own 
event-time cutoff at that cutoff solved at the late-events watermark, capped at 
that watermark, and keep the whole-input start for the first batch of a run 
and, in every batch, for an input evicted through the whole-input fallback, 
whose start already equals the previous batch's cutoff. Commit d0a9623720e 
started the scan at the event time's own cutoff in every batch; commit 
3aaff10de1a replaced it with the whole-input cutoff in every batch, and its 
commit message gives no reason, while the author's reply explains that the 
whole-input start covers state left by an earlier version or the legacy mode 
without a full scan after a restart. The fix keeps the 3aaff10de1a start for 
the first batch of a run and takes the d0a9623720e start for later batches. Add 
join state watermark helper tests and a multi-batch join test.
   
   **Why this works:** IncrementalExecution passes isFirstBatch to 
getStateWatermarkPredicates. When the previous batch ran in this execution, it 
computes prevStateValueWatermark from the same solve that gave this batch's 
cutoff, evaluated at the late-events watermark: the event time's own solve, 
capped at that watermark, when getStateValueWatermarkColumn picked the event 
time, and the whole-input solve, as now, for the fallback; that value is the 
cutoff the previous batch evicted to. In the first batch of a run it keeps the 
whole-input solve, so the startTimestamp contract holds in both cases and 
steady-state scans no longer cross already-evicted ranges.
   
   **Compatibility:** This change alters no join output or state contents in 
any batch; only the point where each state format 4 eviction scan starts 
changes.
   
   **Risks:** If a later change let a batch of a run evict by a different rule 
than its predecessor in the same run, a scan starting at the event time's own 
cutoff would skip entries between the two cutoffs, leaving them in state and 
losing their outer rows; the fix relies on the mode and the eviction column 
staying fixed within a run.
   
   **Constraints:** The first batch of every run, including a restart from an 
earlier version, from the legacy mode, or from a 4.3 checkpoint, keeps the 
whole-input start. An input evicted through the whole-input fallback, such as 
one bounded only through a column cast to TIMESTAMP, keeps its current start in 
every batch, because its cutoff is the whole-input solve. Inputs evicted by a 
column other than their event time keep passing no lower bound.
   
   **Exclusions:**
   - A lower bound for inputs evicted by a column other than their event time, 
which the decision challenge about scanning from the start of the index leaves 
to the author.
   
   **Verification:**
   - **Behavior:** For an input whose condition bounds its event time and 
another column with a lower cutoff, the computed previous state watermark is 
the whole-input cutoff at the late-events watermark in the first batch of a run 
and the event time's own cutoff at that watermark in later batches; it is the 
whole-input cutoff in every batch for an input bounded only through a column 
cast to TIMESTAMP, and absent for an input evicted by another column.
   - **Regression:** On state format 4, a left outer join on `leftTime >= 
rightTime - INTERVAL 10 SECONDS AND expiry >= rightTime - INTERVAL 100 SECONDS` 
run over several batches without a restart emits every unmatched left row once 
its leftTime falls to the event-time cutoff and keeps no evicted row in state, 
as with the current start.
   - **Compatibility:** A restart of that join from a run with 
spark.sql.streaming.statefulOperator.allowMultiple set to false still emits, in 
its first batch, the outer rows of left rows whose leftTime lies between the 
two cutoffs.



##########
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:
   **Nit (P3):** The check in doExecute 
(StreamingSymmetricHashJoinExec.scala:367-392) fails for version 0 only when 
the value predicate tests a column other than the event time, which happens 
only in the default mode when the pick returns another TIMESTAMP column. A 
legacy-mode query and a default-mode join bounded only through `CAST(leftDate 
AS TIMESTAMP)` therefore restart with version 0 although their conditions do 
not bound the event time, an explicit 0 also fails a fresh default-mode start, 
and version 1 orders the cast-bounded input by its event time, not by the 
column the condition bounds. Describing version 1 as the column the default 
mode evicts the input by, and version 0 as failing in the default mode when 
that column is a TIMESTAMP column other than the event time, would match the 
check.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60667#discussion_r4615752134).
   
   **Verification:**
   - **Inspection:** The doc of 
spark.sql.streaming.join.stateFormatV4.indexVersion says that version 0 fails 
only in the default mode when an input is evicted by a TIMESTAMP column other 
than its event time, that the legacy mode runs with version 0, and that version 
1 orders an input bounded only through a cast column by its event time.



##########
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:
   **Nit (P3):** The only test that reaches this branch, 'V4 restart fails when 
the legacy mode changes and the condition bounds another column, legacy 
first=false', fails on the left input, so the right input's entry is never 
evaluated and no restart through the branch succeeds. A change that rejects 
every legacy-mode restart of a version-1 checkpoint, such as one of a 
time-interval join whose eviction column is the event time in both modes, or 
that checks the right input against the wrong attributes, would pass the suite. 
A passing legacy-mode restart of a version-1 time-interval join and a right 
outer variant of the failing case would pin both.
   
   **Verification:**
   - **Compatibility:** A state format 4 left outer join on `rightTime BETWEEN 
leftTime AND leftTime + INTERVAL 10 MINUTES`, started in the default mode and 
restarted with allowMultiple set to false, restarts without error and emits its 
matches and unmatched rows across the restart.
   - **Regression:** A state format 4 right outer join on `rightTime BETWEEN 
leftTime AND expiry`, with the expiry input on the right, started in the 
default mode and restarted with allowMultiple set to false, fails with 
STREAMING_JOIN_STATE_V4_CHECKPOINT_INCOMPATIBLE for the right input and 
`expiry`.



##########
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:
   **Nit (P3):** In the note's own example, `rightTime BETWEEN leftTime AND 
expiry` also constrains leftTime, so 'bounds ... only through another TIMESTAMP 
column' identifies expiry only for a reader who knows that 'bounds' means a 
lower bound from the other input's watermark. The note also leaves out the NULL 
rule: in the default mode a left outer join on `rightTime BETWEEN leftTime AND 
leftTime + INTERVAL 10 MINUTES` now emits `(row, null)` on arrival for a row 
whose leftTime is NULL, which 4.3 kept in state and never emitted, and after 
the upgrade it emits the outer rows of such rows that a state format 1-3 
checkpoint already holds. Wording the scope by what limits how long a row can 
match, and adding a sentence on rows whose eviction column is NULL, would let 
users tell whether their join changes.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60667#discussion_r4615752219).
   
   **Verification:**
   - **Inspection:** The 4.3-to-4.4 note names the joins whose eviction changes 
without relying on the word 'bounds' alone, and it has a sentence on rows whose 
eviction column is NULL that covers both arriving rows and rows already in a 
state format 1-3 checkpoint.



##########
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:
   **Nit (P3):** The new catalyst test pins the event time ahead of other 
columns, but not the order among two other TIMESTAMP columns that both bound 
the input. Index version 1 records that order only implicitly, so if a later 
release iterated the condition's references instead of the input attributes, a 
checkpoint whose state is ordered by expiry would be evicted with deadline's 
cutoff for `rightTime <= expiry AND rightTime <= deadline - INTERVAL 1 HOUR`, 
removing rows that can still match, and the restart check would not notice. An 
assertion with two bounding TIMESTAMP columns in each input order would pin it.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60667#discussion_r4615752123).
   
   **Verification:**
   - **Behavior:** For an input with the event time leftTime and two TIMESTAMP 
columns expiry and deadline, and a condition that bounds expiry and deadline 
but not leftTime, the pick returns whichever of expiry and deadline comes first 
in input order.



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