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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -680,9 +680,12 @@ case class StreamingSymmetricHashJoinExec(
       joinStateManagerStoreGenerator: JoinStateManagerStoreGenerator,
       joinKeyOrdinalForWatermark: Option[Int]) {
 
-    // Filter the joined rows based on the given condition.
-    val preJoinFilter =
-      Predicate.create(preJoinFilterExpr.getOrElse(Literal(true)), 
inputAttributes).eval _
+    // Filter the joined rows based on the given condition. A row whose 
watermarked join key is
+    // NULL can never match, and eviction by that key may never reach it, so 
it fails this filter.
+    val preJoinFilter = Predicate.create(
+      (preJoinFilterExpr ++ joinKeyOrdinalForWatermark.map(i => 
IsNotNull(joinKeys(i))))

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 as suggested. The pre-join filter is master's again, and the NULL test 
reads the key row that `keyGenerator` already produced (`key.isNullAt` at the 
watermark ordinal). So a computed key is evaluated once per row, as on master, 
and the side-only conjuncts still run first.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/operators/stateful/join/StreamingSymmetricHashJoinExec.scala:
##########
@@ -680,9 +680,12 @@ case class StreamingSymmetricHashJoinExec(
       joinStateManagerStoreGenerator: JoinStateManagerStoreGenerator,
       joinKeyOrdinalForWatermark: Option[Int]) {
 
-    // Filter the joined rows based on the given condition.
-    val preJoinFilter =
-      Predicate.create(preJoinFilterExpr.getOrElse(Literal(true)), 
inputAttributes).eval _
+    // Filter the joined rows based on the given condition. A row whose 
watermarked join key is
+    // NULL can never match, and eviction by that key may never reach it, so 
it fails this filter.

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([SPARK-61382](https://issues.apache.org/jira/browse/SPARK-61382)) at the 
NULL test, naming NULLs in the other equality keys and the rows with a NULL 
watermarked key that a checkpoint already holds.



##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingJoinSuite.scala:
##########
@@ -2069,6 +2069,74 @@ abstract class StreamingOuterJoinBase extends 
StreamingJoinSuite {
     }
   }
 
+  for {
+    joinType <- Seq("inner", "left_outer", "full_outer")
+    windowKey <- Seq(true, false)
+    nullsInFirstBatch <- Seq(true, false)
+  } {
+    val keyType = if (windowKey) "window" else "timestamp"
+    val batch = if (nullsInFirstBatch) "the first" else "a later"
+    test(s"SPARK-62046: $joinType join with NULL watermarked $keyType keys in 
$batch batch") {
+      val leftInput = MemoryStream[(Int, Int)]
+      val nullInput = MemoryStream[Int]
+      val rightInput = MemoryStream[(Int, Int)]
+      val leftWithTime = leftInput.toDF().toDF("lk", "t")
+        .select($"lk", timestamp_seconds($"t").as("lt"))
+        .withWatermark("lt", "10 seconds")
+      val keyed = leftWithTime.select($"lk",
+        (if (windowKey) window($"lt", "10 seconds") else $"lt").as("lw"))
+      // A union keeps the watermark on lw, which is NULL for the rows of 
nullInput.
+      val left = keyed.union(nullInput.toDF().toDF("lk")
+        .select($"lk", lit(null).cast(keyed.schema("lw").dataType).as("lw")))
+      // The right key has no watermark and is NULL for a negative input.
+      val rightTime = when($"s" >= 0, timestamp_seconds($"s"))
+      val rightKey = if (windowKey) {
+        when($"s" >= 0, struct(rightTime.as("start"),
+          (rightTime + expr("INTERVAL 10 SECONDS")).as("end")))
+      } else {
+        rightTime
+      }
+      val right = rightInput.toDF().toDF("rk", "s").select($"rk", 
rightKey.as("rw"))
+      val (leftEnd, rightEnd) = if (windowKey) ($"lw.end", $"rw.end") else 
($"lw", $"rw")
+      val joined = left.join(right, expr("lk = rk AND lw = rw"), joinType)

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: in half of the matrix cases, the left outer join has `lk > 0` and the 
full outer join `lk > 0 AND rk > 0`, conjuncts on preserved inputs that all 
rows pass, so they stay in the join as pre-join filters. With the NULL test now 
on the key row, it no longer depends on the pre-join filter at all.



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