Commit e2db766
authored
fix nth_value window function negates i64::MIN (#22304)
## Which issue does this PR close?
- Closes #22222.
## Rationale for this change
`nth_value` could panic at execution time when called with `i64::MIN` as
the `n` argument. The implementation supports negative `n` for reverse
indexing and negated the value internally, but negating `i64::MIN`
overflows. This caused a runtime panic instead of returning a normal
DataFusion error for invalid input.
## What changes are included in this PR?
This PR adds validation for the second argument of `nth_value` so that
`i64::MIN` is rejected before any negation occurs. Instead of panicking
during execution, the function now returns a regular execution error.
This PR also adds regression coverage at two levels:
- a unit test for the `nth_value` window function implementation
- a sqllogictest case covering the SQL query shape that previously
triggered the panic
## Are these changes tested?
Yes.
The change is covered by:
1. a focused unit test in the window function implementation
2. a SQL logic test in `window.slt`
Validated with:
1. `cargo test -p datafusion-functions-window nth_value --lib`
2. `cargo test -p datafusion-sqllogictest --test sqllogictests window`
## Are there any user-facing changes?
Yes. Queries that previously panicked when calling `nth_value(...,
-9223372036854775808)` now return a proper execution error instead.1 parent a786471 commit e2db766
2 files changed
Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
128 | 136 | | |
129 | 137 | | |
130 | 138 | | |
| |||
287 | 295 | | |
288 | 296 | | |
289 | 297 | | |
| 298 | + | |
290 | 299 | | |
291 | 300 | | |
292 | 301 | | |
| |||
660 | 669 | | |
661 | 670 | | |
662 | 671 | | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
663 | 692 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1218 | 1222 | | |
1219 | 1223 | | |
1220 | 1224 | | |
| |||
0 commit comments