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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/IncrementalExecution.scala:
##########
@@ -630,6 +661,134 @@ class IncrementalExecution(
       watermarkPropagator.propagate(currentBatchId, plan, 
watermarkForCurrBatch)
     }
 
+    /**
+     * Find, for each stateful operator that applies its input watermark to an 
event-time column,
+     * which stream-stream join inputs' event times that column carries. The 
walk follows the
+     * column down through nodes that pass it on unchanged, to the same 
position in every input
+     * of a union, through windows built from it, which end after it, and into 
the one input of
+     * a node with several inputs, such as a stream-static join, that outputs 
it. It stops at a
+     * stream-stream join, at another operator that writes state or sets an 
event time, and at
+     * any node it does not recognize; a join that no traced column reaches 
holds back for both
+     * inputs.
+     */
+    private def joinWatermarkConsumers(plan: SparkPlan): 
Seq[JoinWatermarkConsumer] = {
+      def eventTime(output: Seq[Attribute]): Option[Attribute] =
+        output.find(_.metadata.contains(EventTimeWatermark.delayKey))
+
+      // A time or session window built from one column, plus constants, ends 
after that column.
+      def windowSource(window: Attribute, expression: Expression): 
Option[Attribute] = {
+        val isWindow = window.metadata.contains(TimeWindow.marker) ||
+          window.metadata.contains(SessionWindow.marker)
+        expression.references.toSeq match {
+          case Seq(source) if isWindow => Some(source)
+          case _ => None
+        }
+      }
+
+      def passThrough(child: SparkPlan, attribute: Attribute): Seq[(Long, 
JoinSide, Attribute)] =
+        child.output.find(_.exprId == 
attribute.exprId).toSeq.flatMap(findJoinSides(child, _))
+
+      def findJoinSides(
+          node: SparkPlan,
+          attribute: Attribute): Seq[(Long, JoinSide, Attribute)] = {
+        node match {
+          case j: StreamingSymmetricHashJoinExec =>
+            val side = if (eventTime(j.left.output).exists(_.exprId == 
attribute.exprId)) {
+              Some(LeftSide)
+            } else if (eventTime(j.right.output).exists(_.exprId == 
attribute.exprId)) {
+              Some(RightSide)
+            } else {
+              None
+            }
+            j.stateInfo.map(_.operatorId).zip(side).map { case (id, s) => (id, 
s, attribute) }
+              .toSeq
+          case p: ProjectExec =>
+            p.projectList.find(_.exprId == attribute.exprId).toSeq.flatMap {
+              case a: Attribute => passThrough(p.child, a)
+              case Alias(a: Attribute, _) => passThrough(p.child, a)
+              case alias: Alias =>

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 in 
[90dfad8d848](https://github.com/apache/spark/pull/60279/commits/90dfad8d84808a6c4e00b41b0c6ffa24c713db31).
 The tracer now follows a column that adds constant intervals
   with no negative part to an event time, such as `impressionTime + INTERVAL 1 
MINUTE` or a month
   interval. Such a column never falls below that event time, in any time zone, 
so the bounded
   input's state watermark also bounds it. Every other computed column, such as 
one that subtracts
   an interval, adds a negative one, truncates or calls a UDF, still holds the 
join back for both
   inputs, and a comment at that fallback says why. I left `greatest()` out to 
keep the rule small:
   it still holds back, so the compatibility tests that use it as an untraced 
column keep their
   meaning. The tracer's doc comment and the migration note now say which 
computed columns Spark
   follows. The restart check reads the same tracer, so it now counts only the 
bounded input for
   such a column.
   
   Tests: a deduplication over a union whose join child shifts the event time 
by one minute, and by
   one month. Over the impression time, the join follows the impression input 
and forwards its
   state watermark; over the click time, it holds back at 0. A column one 
second below the
   impression time, written as a subtraction or as a negative interval, holds 
back for both inputs.
   
   <!-- sp2k-review11 reply 4597569654 -->
   



##########
docs/streaming/ss-migration-guide.md:
##########
@@ -25,6 +25,44 @@ Please refer [Migration Guide: SQL, Datasets and 
DataFrame](../sql-migration-gui
 
 ## Upgrading from Structured Streaming 4.3 to 4.4
 
+- Spark 4.4 holds back the output watermark of a stream-stream join when 
retained state can
+  still emit old event times. Downstream stateful operators may retain more 
state, take longer
+  to finalize results, or stop making progress while the join has no 
event-time eviction bound.
+  The join holds back only for an input whose event time reaches the next 
stateful operator: in
+  a join on `clickTime <= impressionTime + INTERVAL 1 HOUR`, a window 
aggregation over
+  `impressionTime` makes progress, and one over `clickTime` does not. Spark 
follows the event
+  time through projections, filters, unions, and time and session windows, to 
aggregations,

Review Comment:
   > [!NOTE]
   > **DISCLAIMER:** This comment was written by an LLM: Claude Sonnet 5.5 
(`claude-sonnet-5-5`, 1M context), running as an SP2K agent on behalf of 
@HeartSaVioR.
   
   Fixed in 
[90dfad8d848](https://github.com/apache/spark/pull/60279/commits/90dfad8d84808a6c4e00b41b0c6ffa24c713db31).
 The migration note now says that Spark follows the event time through 
projections, filters, unions, stream-static joins and time and session windows, 
and names the operators that it counts as `flatMapGroupsWithState` and 
`applyInPandasWithState` with event-time timeouts and `transformWithState` in 
event-time mode, next to aggregations, deduplication and stream-stream joins.
   
   <!-- sp2k-review11 reply 4597569671 -->
   



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