viirya commented on code in PR #8410:
URL: https://github.com/apache/arrow-datafusion/pull/8410#discussion_r1413246702
##########
datafusion/expr/src/window_frame.rs:
##########
@@ -148,18 +148,20 @@ impl WindowFrame {
pub fn regularize(mut frame: WindowFrame, order_bys: usize) ->
Result<WindowFrame> {
if frame.units == WindowFrameUnits::Range && order_bys != 1 {
// Normally, RANGE frames require an ORDER BY clause with exactly one
- // column. However, an ORDER BY clause may be absent in two edge cases.
+ // column. However, an ORDER BY clause may be absent in two edge cases:
+ // 1. start bound is UNBOUNDED or CURRENT ROW
+ // 2. end bound is CURRENT ROW or UNBOUNDED.
+ // In these cases, we regularize the RANGE frame to be equivalent to a
ROWS
+ // frame with the UNBOUNDED bounds.
Review Comment:
So DataFusion is following Postgres behavior on this.
```
postgres=# select a, rank() over (partition by a RANGE between 1 PRECEDING
AND 2 FOLLOWING) rnk from (select 1 a) q;
ERROR: RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY
column
LINE 1: select a, rank() over (partition by a RANGE between 1 PRECED...
^
postgres=# select a, rank() over (partition by a RANGE between UNBOUNDED
PRECEDING AND UNBOUNDED FOLLOWING) rnk from (select 1 a) q;
a | rnk
---+-----
1 | 1
(1 row)
```
--
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]