siying commented on code in PR #60068:
URL: https://github.com/apache/spark/pull/60068#discussion_r4572052498


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/MicroBatchExecution.scala:
##########
@@ -856,7 +873,7 @@ class MicroBatchExecution(
       execCtx: MicroBatchExecutionContext,
       sparkSessionToRunBatches: SparkSession): Unit = {
     execCtx.sinkCommitProgress = None
-    offsetLog.getLatest() match {
+    initialLatestOffsetSeq match {

Review Comment:
   **[P1] Read the latest offset after RTM recovery purges uncommitted entries**
   
   When an RTM query fails after writing an offset entry but before its commit 
entry, `initializeExecution` deletes that offset with `purgeAfter`. This cached 
value still refers to the deleted batch. With async progress tracking, 
`validateOffsetLogAndGetPrevOffset` calls `getPrevBatchFromStorage` for that 
batch; the helper returns `None` when all remaining files have smaller batch 
IDs. Consequently, `startOffsets` stays empty and the RTM path in `runBatch` 
uses `stream.initialOffset`, replaying already committed history. This also 
affects stateless queries without joins.
   
   Could we read the post-purge latest offset here and apply retention 
normalization to that result? The existing `StreamRealTimeModeSuite` test 
`purge offsetLog when it doesn't match with the commit log`, with async 
progress tracking enabled, covers this recovery boundary. This finding is 
source-traced; I have not run the test.



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/runtime/IncrementalExecution.scala:
##########
@@ -721,7 +722,15 @@ class IncrementalExecution(
     }
 
     override def apply(plan: SparkPlan): SparkPlan = {
-      val planWithStateOpId = plan transform composedRule
+      val useRetainedEventTimeColumn =
+        sparkSession.sessionState.conf.getConf(
+          SQLConf.STREAMING_JOIN_EVENT_TIME_COLUMN_RETENTION_VERSION) == 1 &&
+          plan.collect { case _: StreamingSymmetricHashJoinExec => true }.size 
== 1
+      val planWithRetentionMode = plan.transform {
+        case join: StreamingSymmetricHashJoinExec =>
+          join.copy(useRetainedEventTimeColumn = useRetainedEventTimeColumn)

Review Comment:
   **[P1] Preserve the retention decision through CTE expansion**
   
   The logical and physical join counts can disagree. In `WITH j AS 
MATERIALIZED (...) SELECT * FROM j UNION ALL SELECT * FROM j`, `ColumnPruning` 
sees one join in the CTE definition and retains its event-time columns. 
`ReplaceCTERefWithRepartition` then expands both references after the final 
pruning pass, so this count sees two physical joins and sets 
`useRetainedEventTimeColumn=false` on both.
   
   For the existing regression's condition `l.key = r.key AND l.leftJoinTime > 
r.rightEventTime`, with a separate watermarked `l.leftEventTime`, the legacy 
helper now derives the cutoff from `leftJoinTime` and applies it to the newly 
retained `leftEventTime`. A buffered left row with event time 20s and join time 
200s is evicted when the watermark reaches 95s, losing its valid later match 
with right event time 150s. Before this change, the unused left event-time 
column was pruned and that eviction predicate was absent.
   
   Could we preserve the logical retention decision during physical planning 
and extend the unrelated-timestamp regression with this twice-referenced 
materialized CTE? This finding is source-traced; I have not executed that 
variant.



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