petern48 commented on code in PR #19278:
URL: https://github.com/apache/datafusion/pull/19278#discussion_r2618056245


##########
datafusion/sqllogictest/test_files/aggregate.slt:
##########
@@ -991,6 +991,89 @@ SELECT approx_median(col_f64_nan) FROM median_table
 ----
 NaN
 
+# median_sliding_window
+statement ok
+CREATE TABLE median_window_test (
+    timestamp INT,
+    tags VARCHAR,
+    value DOUBLE
+);
+
+statement ok
+INSERT INTO median_window_test (timestamp, tags, value) VALUES
+(1, 'tag1', 10.0),
+(2, 'tag1', 20.0),
+(3, 'tag1', 30.0),
+(4, 'tag1', 40.0),
+(5, 'tag1', 50.0),
+(1, 'tag2', 60.0),
+(2, 'tag2', 70.0),
+(3, 'tag2', 80.0),
+(4, 'tag2', 90.0),
+(5, 'tag2', 100.0);
+
+query ITRR
+SELECT
+    timestamp,
+    tags,
+    value,
+    median(value) OVER (
+        PARTITION BY tags
+        ORDER BY timestamp
+        ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
+    ) AS value_median_3
+FROM median_window_test
+ORDER BY tags, timestamp;
+----
+1 tag1 10 15
+2 tag1 20 20
+3 tag1 30 30
+4 tag1 40 40
+5 tag1 50 45
+1 tag2 60 65
+2 tag2 70 70
+3 tag2 80 80
+4 tag2 90 90
+5 tag2 100 95
+
+# median_non_sliding_window
+query ITRRRR
+SELECT
+    timestamp,
+    tags,
+    value,
+    median(value) OVER (
+        PARTITION BY tags
+        ORDER BY timestamp
+        ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
+    ) AS value_median_unbounded_preceding,
+    median(value) OVER (
+        PARTITION BY tags
+        ORDER BY timestamp
+        ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
+    ) AS value_median_unbounded_both,

Review Comment:
   Ah, so you're saying `unbounded preceding` is supposed to work even without 
`retract_batch()` implemented. I was originally under the impression that it 
wasn't, but no that makes total sense now.
   
   In that case, I think this PR is already fixes the bug, so there's no need 
to submit an issue for that. I mentioned in [this 
comment](https://github.com/apache/datafusion/pull/19278#discussion_r2616516125)
 that passing `mut` instead of clearing state with `take()` 
(https://github.com/apache/datafusion/pull/19278/commits/81ced74f3a858dfe93e66a6d800cfea36ad32daf)
 fixes the results in the `mod.rs` test. I've verified this by copying that 
change 
(https://github.com/apache/datafusion/pull/19278/commits/81ced74f3a858dfe93e66a6d800cfea36ad32daf)
 over to main and testing it, and the results for that test change. It's 
completely unrelated to the new support for `retract_batch()`. We just have an 
integer overflow issue remaining, which I've submitted an issue for.



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