Skip to content

Commit 16589b5

Browse files
authored
Fix: handle NULL offset of NTH_VALUE window function (#12851)
1 parent 21cb357 commit 16589b5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

datafusion/physical-expr/src/window/nth_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl PartitionEvaluator for NthValueEvaluator {
185185
// Negative index represents reverse direction.
186186
(n_range >= reverse_index, true)
187187
}
188-
Ordering::Equal => (true, false),
188+
Ordering::Equal => (false, false),
189189
}
190190
}
191191
};

datafusion/sqllogictest/test_files/window.slt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4929,6 +4929,15 @@ SELECT v1, NTH_VALUE(v2, 0) OVER (PARTITION BY v1 ORDER BY v2) FROM t;
49294929
2 NULL
49304930
2 NULL
49314931

4932+
query I
4933+
SELECT NTH_VALUE(tt0.v1, NULL) OVER (PARTITION BY tt0.v2 ORDER BY tt0.v1) FROM t AS tt0;
4934+
----
4935+
NULL
4936+
NULL
4937+
NULL
4938+
NULL
4939+
NULL
4940+
49324941
statement ok
49334942
DROP TABLE t;
49344943

0 commit comments

Comments
 (0)