Skip to content

fix nth_value window function negates i64::MIN#22304

Open
xiedeyantu wants to merge 3 commits into
apache:mainfrom
xiedeyantu:nth_value
Open

fix nth_value window function negates i64::MIN#22304
xiedeyantu wants to merge 3 commits into
apache:mainfrom
xiedeyantu:nth_value

Conversation

@xiedeyantu
Copy link
Copy Markdown
Member

Which issue does this PR close?

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.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: nth_value window function negates i64::MIN

1 participant