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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/StreamingJoinHelper.scala:
##########
@@ -186,6 +297,14 @@ object StreamingJoinHelper extends PredicateHelper with 
Logging {
       return None
     }
 
+    // State eviction compares this cutoff in timestamp units against the 
constrained column.
+    val hasTimestampStateAttribute = constraintTerm.exists {
+      case a: AttributeReference =>
+        attributesToFindStateWatermarkFor.contains(a) && a.dataType == 
TimestampType

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.
   
   Confirmed: a whole-window comparison such as `lw > rw` no longer bounds 
state, so outer and left semi joins bounded only that way fail analysis, and 
inner joins keep that input's state. We are keeping this. Master accepted these 
comparisons for any window lengths, and that is wrong when the stored windows 
are shorter: with 10-second left windows and 20-second sliding right windows, 
master evicts a left window, and then a later right window still matches it. 
Telling the safe and unsafe cases apart needs window lengths that the 
attributes do not carry, so supporting it would add new metadata to every 
window column, for a form the guide does not document. The guides now say that 
comparing time windows does not qualify, and new tests pin the rejection and 
the inner-join match that eviction would lose 
([f885a5a0876](https://github.com/apache/spark/pull/60283/commits/f885a5a08766d0a1ce402ab9dff35dce9af28b98)).
   
   <!-- sp2k-review1 reply 4523339214 -->
   



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UnsupportedOperationChecker.scala:
##########
@@ -706,32 +707,44 @@ object UnsupportedOperationChecker extends Logging {
   }
 
   private def checkForStreamStreamJoinWatermark(join: Join): Unit = {
-    val watermarkInJoinKeys = StreamingJoinHelper.isWatermarkInJoinKeys(join)
-
-    // Check if the nullable side has a watermark, and there's a range 
condition which
-    // implies a state value watermark on the first side.
-    val hasValidWatermarkRange = join.joinType match {
-      case LeftOuter | LeftSemi => StreamingJoinHelper.getStateValueWatermark(
-        join.left.outputSet, join.right.outputSet, join.condition, 
Some(1000000)).isDefined
-      case RightOuter => StreamingJoinHelper.getStateValueWatermark(
-        join.right.outputSet, join.left.outputSet, join.condition, 
Some(1000000)).isDefined
-      case FullOuter =>
-        Seq((join.left.outputSet, join.right.outputSet),
-          (join.right.outputSet, join.left.outputSet)).exists {
-          case (attributesToFindStateWatermarkFor, 
attributesWithEventWatermark) =>
-            
StreamingJoinHelper.getStateValueWatermark(attributesToFindStateWatermarkFor,
-              attributesWithEventWatermark, join.condition, 
Some(1000000)).isDefined
-        }
+    val keys = ExtractEquiJoinKeys.unapply(join)
+    val leftKeys = keys.map(_._2).getOrElse(Nil)
+    val rightKeys = keys.map(_._3).getOrElse(Nil)
+
+    def canEvictState(
+        stateInput: LogicalPlan,
+        otherInput: LogicalPlan,
+        otherKeys: Seq[Expression]): Boolean = {
+      val eventTime = 
otherInput.output.find(_.metadata.contains(EventTimeWatermark.delayKey))
+      StreamingJoinHelper.getStateKeyWatermarkOrdinal(otherKeys, 
otherInput.output).isDefined ||
+        StreamingJoinHelper.getStateValueWatermark(stateInput.outputSet,
+          AttributeSet(eventTime.toSeq), join.condition, 
Some(1000000)).isDefined
+    }
+
+    val leftCanEvict = canEvictState(join.left, join.right, rightKeys)
+    val rightCanEvict = canEvictState(join.right, join.left, leftKeys)
+    val hasRequiredWatermarks = join.joinType match {
+      case LeftOuter | LeftSemi => leftCanEvict
+      case RightOuter => rightCanEvict
+      case FullOuter => leftCanEvict && rightCanEvict
       case _ =>
         throwError(
           s"Join type ${join.joinType} is not supported with streaming 
DataFrame/Dataset")(join)
     }
 
-    if (!watermarkInJoinKeys && !hasValidWatermarkRange) {
+    if (!hasRequiredWatermarks) {
+      val requirement = join.joinType match {
+        case FullOuter => "watermarks on both inputs and time constraints in 
both directions"
+        case RightOuter => "a watermark on the left input and a time 
constraint"
+        case _ => "a watermark on the right input and a time constraint"
+      }
       throwError(
         s"Stream-stream ${join.joinType} join between two streaming 
DataFrame/Datasets " +
-          "is not supported without a watermark in the join keys, or a 
watermark on " +
-          "the nullable side and an appropriate range condition")(join)
+          s"is not supported: it requires $requirement " +
+          "that allow unmatched state to be finalized. " +
+          "The time constraint may be equality on event time or a time range 
condition. " +

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, fixed: the message keeps its current text and adds that a time range 
condition must bound a TIMESTAMP column of the finalized input by the other 
input's event time. The numeric, DATE, TIMESTAMP_NTZ and window tests assert 
the new sentence 
([f885a5a0876](https://github.com/apache/spark/pull/60283/commits/f885a5a08766d0a1ce402ab9dff35dce9af28b98)).
   
   <!-- sp2k-review1 reply 4523339228 -->
   



##########
docs/streaming/apis-on-dataframes-and-datasets.md:
##########
@@ -1435,6 +1444,11 @@ Additional details on supported joins:
 
 - Joins can be cascaded, that is, you can do `df1.join(df2, ...).join(df3, 
...).join(df4, ....)`.
 
+- For stream-stream outer and semi joins, the time constraint that finalizes 
an input's rows must
+  bound a timestamp column of that input by the other input's event time, 
through an equality key

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, fixed: the join guide and the migration note now apply the 
TIMESTAMP-column rule to range conditions only, and still list equality on the 
other input's event time or its time window as a qualifying constraint 
([f885a5a0876](https://github.com/apache/spark/pull/60283/commits/f885a5a08766d0a1ce402ab9dff35dce9af28b98)).
   
   <!-- sp2k-review1 reply 4523339235 -->
   



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