fix nth_value window function negates i64::MIN#22304
Open
xiedeyantu wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
nth_valuecould panic at execution time when called withi64::MINas thenargument. The implementation supports negativenfor reverse indexing and negated the value internally, but negatingi64::MINoverflows. 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_valueso thati64::MINis 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:
nth_valuewindow function implementationAre these changes tested?
Yes.
The change is covered by:
window.sltValidated with:
cargo test -p datafusion-functions-window nth_value --libcargo test -p datafusion-sqllogictest --test sqllogictests windowAre there any user-facing changes?
Yes. Queries that previously panicked when calling
nth_value(..., -9223372036854775808)now return a proper execution error instead.