WweiL commented on code in PR #44076:
URL: https://github.com/apache/spark/pull/44076#discussion_r1408970548


##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/MultiStatefulOperatorsSuite.scala:
##########
@@ -878,6 +878,147 @@ class MultiStatefulOperatorsSuite
     testOutputWatermarkInJoin(join3, input1, -40L * 1000 - 1)
   }
 
+  test("SPARK-45637 window agg + window agg -> join on window, append mode") {
+    val impressions = MemoryStream[Int]
+    val clicks = MemoryStream[Int]
+
+    val impressionsWithWatermark = impressions.toDF()
+      .withColumn("impressionTime", timestamp_seconds($"value"))
+      .withColumnRenamed("value", "impressionAdId")
+      .withWatermark("impressionTime", "0 seconds")
+
+    // clickTime is always later than impressionTime for clickAdId = 
impressionAdId
+    // Here we manually set the difference to 2 seconds (see the 
(Multi)AddData below)
+    val clicksWithWatermark = clicks.toDF()
+      .withColumn("timeSec", timestamp_seconds($"value"))
+      .selectExpr("value as clickAdId", "timeSec + INTERVAL 2 seconds as 
clickTime")
+      .withWatermark("clickTime", "0 seconds")
+
+    val clicksWindow = clicksWithWatermark.groupBy(
+      window($"clickTime", "5 seconds")
+    ).count()
+
+    val impressionsWindow = impressionsWithWatermark.groupBy(
+      window($"impressionTime", "5 seconds")
+    ).count()
+
+    val clicksAndImpressions = clicksWindow.join(impressionsWindow, "window", 
"inner")
+
+    withSQLConf((SQLConf.SHUFFLE_PARTITIONS.key, "1")) {
+      testStream(clicksAndImpressions)(
+        MultiAddData(
+          (impressions, Seq(0 to 8: _*)),
+          (clicks, Seq(6))
+        ),
+        // data batch triggered
+
+        // global watermark: (0, 0) [drop, evict]
+        // impression [impressionAdId, impressionTime]:
+        //    wm:     (0, 0)
+        //    input:  (0, 0), (1, 1), (2, 2), (3, 3), ..., (8, 8)
+        //    agg:    [0, 5) -> 5, [5, 10) -> 4
+        //    state:  [0, 5) -> 5, [5, 10) -> 4
+        //    output: None
+        // click [clickAdId, clickTime]
+        //    wm:     (0, 0)
+        //    input:  (6, 8)
+        //    agg:    [0, 5) -> 0, [5, 10) -> 1
+        //    state:  [0, 5) -> 0, [5, 10) -> 1
+        //    output: None
+        // join:
+        //    all None
+
+        // no-data batch triggered (shouldRunAnotherBatch)
+
+        // global watermark: (0, 8) (default is min across multiple watermarks)
+        // impression:
+        //    wm:     (0, 8)
+        //    input:  None
+        //    agg:    None
+        //    state:  [5, 10) -> 4
+        //    output: [0, 5) -> 5 (actually no, the state is not evicting any 
rows, why?)

Review Comment:
   why? logs see the description



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to