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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -733,5 +734,55 @@ object UnsupportedOperationChecker extends Logging {
           "is not supported without a watermark in the join keys, or a 
watermark on " +
           "the nullable side and an appropriate range condition")(join)
     }
+
+    if 
(SQLConf.get.getConf(SQLConf.STREAMING_JOIN_CHECK_WATERMARK_DIRECTION_ENABLED)) 
{
+      checkStreamStreamJoinWatermarkDirection(join)
+    }
+  }
+
+  /**
+   * The rows of an input that the join outputs once, unmatched rows of an 
outer join or the
+   * matched rows of a left semi join, are final only if later rows of the 
other input cannot
+   * match them. So the other input's watermark must bound this input's state, 
through the
+   * equality key that eviction uses or through a range condition.
+   */
+  private def checkStreamStreamJoinWatermarkDirection(join: Join): Unit = {
+    val (leftKeys, rightKeys) = join match {
+      case ExtractEquiJoinKeys(_, leftKeys, rightKeys, _, _, _, _, _) => 
(leftKeys, rightKeys)
+      case _ => (Nil, Nil)
+    }
+    val keyOrdinal = 
StreamingJoinHelper.findJoinKeyOrdinalForWatermark(leftKeys, rightKeys)
+
+    def checkInput(
+        stateSide: String,
+        state: LogicalPlan,
+        otherSide: String,
+        other: LogicalPlan,
+        otherKeys: Seq[Expression]): Unit = {
+      val boundedByKey = keyOrdinal.exists { ordinal =>
+        StreamingJoinHelper.isKeyBoundedByWatermark(otherKeys(ordinal), 
other.outputSet)
+      }
+      val boundedByRange = StreamingJoinHelper.getStateValueWatermark(
+        state.outputSet, other.outputSet, join.condition, 
Some(1000000)).isDefined

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. The range solve now runs only when the key does not already bound 
the input. I kept the
   key extraction separate from the existing check: it runs once per query 
start on the driver,
   and keeping the two checks independent keeps the conf-off path the same as 
before.



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