fornwall commented on code in PR #24515:
URL: https://github.com/apache/datafusion/pull/24515#discussion_r3833581875
##########
datafusion/sqllogictest/test_files/window.slt:
##########
@@ -6948,6 +6948,76 @@ ORDER BY x
62 2
62 2
+# RANGE window frame over a time ORDER BY key. Time is orderable, so free
+# frames can locate peer groups by comparison even though finite offsets do not
+# have suitable frame-bound arithmetic.
+query DI
+SELECT x, COUNT(*) OVER (ORDER BY x)
+FROM (VALUES (arrow_cast('01:00:00', 'Time64(Microsecond)')),
+ (arrow_cast('02:00:00', 'Time64(Microsecond)')),
+ (arrow_cast('02:00:00', 'Time64(Microsecond)'))) t(x)
+ORDER BY x
+----
+01:00:00 1
+02:00:00 3
+02:00:00 3
+
+# A non-aggregate window function and descending order over nanosecond time.
+query DI
+SELECT x, RANK() OVER (ORDER BY x DESC)
+FROM (VALUES (arrow_cast('01:00:00', 'Time64(Nanosecond)')),
+ (arrow_cast('02:00:00', 'Time64(Nanosecond)')),
+ (arrow_cast('02:00:00', 'Time64(Nanosecond)'))) t(x)
+ORDER BY x
+----
+01:00:00 3
+02:00:00 1
+02:00:00 1
+
+# Explicit free bounds use the same comparison-only support.
+query DI
+SELECT x, COUNT(*) OVER (ORDER BY x RANGE BETWEEN CURRENT ROW AND UNBOUNDED
FOLLOWING)
+FROM (VALUES (arrow_cast('01:00:00', 'Time32(Second)')),
+ (arrow_cast('02:00:00', 'Time32(Second)')),
+ (arrow_cast('02:00:00', 'Time32(Second)'))) t(x)
+ORDER BY x
+----
+01:00:00 3
+02:00:00 2
+02:00:00 2
+
+query DI
+SELECT x, COUNT(*) OVER (ORDER BY x)
+FROM (VALUES (arrow_cast('01:00:00.000', 'Time32(Millisecond)')),
+ (arrow_cast('02:00:00.000', 'Time32(Millisecond)')),
+ (arrow_cast('02:00:00.000', 'Time32(Millisecond)'))) t(x)
+ORDER BY x
+----
+01:00:00 1
+02:00:00 3
+02:00:00 3
+
+# A time ORDER BY key nested in a dictionary resolves through the same arm.
+query ?I
+SELECT x, COUNT(*) OVER (ORDER BY x)
+FROM (VALUES (arrow_cast(arrow_cast('01:00:00', 'Time64(Microsecond)'),
'Dictionary(Int32, Time64(Microsecond))')),
+ (arrow_cast(arrow_cast('02:00:00', 'Time64(Microsecond)'),
'Dictionary(Int32, Time64(Microsecond))')),
+ (arrow_cast(arrow_cast('02:00:00', 'Time64(Microsecond)'),
'Dictionary(Int32, Time64(Microsecond))'))) t(x)
+ORDER BY x
+----
+01:00:00 1
+02:00:00 3
+02:00:00 3
+
+# Finite offsets over time are rejected for both the start and end bound.
+query error DataFusion error: type_coercion\ncaused by\nError during planning:
RANGE with offset PRECEDING/FOLLOWING is not supported for ORDER BY type
Time64\(µs\)
+SELECT COUNT(*) OVER (ORDER BY x RANGE BETWEEN INTERVAL '1' HOUR PRECEDING AND
CURRENT ROW)
+FROM (VALUES (arrow_cast('01:00:00', 'Time64(Microsecond)'))) t(x)
+
+query error DataFusion error: type_coercion\ncaused by\nError during planning:
RANGE with offset PRECEDING/FOLLOWING is not supported for ORDER BY type
Time64\(µs\)
+SELECT COUNT(*) OVER (ORDER BY x RANGE BETWEEN CURRENT ROW AND INTERVAL '1'
HOUR FOLLOWING)
+FROM (VALUES (arrow_cast('01:00:00', 'Time64(Microsecond)'))) t(x)
+
Review Comment:
@nuno-faria We should support that as well!
But it requires some work to handle the non-wrapping around midnight part
(ordinary time +/- interval wraps), so I think that's better in a follow up PR.
Does that sound ok?
--
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]