Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion/physical-expr/src/window/nth_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl PartitionEvaluator for NthValueEvaluator {
// Negative index represents reverse direction.
(n_range >= reverse_index, true)
}
Ordering::Equal => (true, false),
Ordering::Equal => (false, false),
}
}
};
Expand Down
9 changes: 9 additions & 0 deletions datafusion/sqllogictest/test_files/window.slt
Original file line number Diff line number Diff line change
Expand Up @@ -4929,6 +4929,15 @@ SELECT v1, NTH_VALUE(v2, 0) OVER (PARTITION BY v1 ORDER BY v2) FROM t;
2 NULL
2 NULL

query I
SELECT NTH_VALUE(tt0.v1, NULL) OVER (PARTITION BY tt0.v2 ORDER BY tt0.v1) FROM t AS tt0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked that without the change in this PR, this test panics as described in the ticket:

thread 'tokio-runtime-worker' panicked at datafusion/physical-expr/src/window/nth_value.rs:195:63:
attempt to subtract with overflow
stack backtrace:
   0: rust_begin_unwind
             at /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_fmt

----
NULL
NULL
NULL
NULL
NULL

statement ok
DROP TABLE t;

Expand Down