You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "xiedeyantu (via GitHub)" <gi...@apache.org> on 2026/05/17 12:01:27 UTC

[PR] fix nth_value window function negates i64::MIN [datafusion]

xiedeyantu opened a new pull request, #22304:
URL: https://github.com/apache/datafusion/pull/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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix nth_value window function negates i64::MIN [datafusion]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #22304:
URL: https://github.com/apache/datafusion/pull/22304#issuecomment-4555137396

   > Would the same issue happen for the aggregate version of this function?
   
   I'm not very familiar with this aggregated version of the function. Could we move this discussion to an issue? Or add it to issue #22222? We can focus on the current issue in this PR.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix nth_value window function negates i64::MIN [datafusion]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #22304:
URL: https://github.com/apache/datafusion/pull/22304#issuecomment-4603810951

   @Jefffrey Can we merge this before anything else?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix nth_value window function negates i64::MIN [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on PR #22304:
URL: https://github.com/apache/datafusion/pull/22304#issuecomment-4609805577

   thanks @xiedeyantu & @kosiew 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix nth_value window function negates i64::MIN [datafusion]

Posted by "xiedeyantu (via GitHub)" <gi...@apache.org>.
xiedeyantu commented on PR #22304:
URL: https://github.com/apache/datafusion/pull/22304#issuecomment-4515693453

   @Dandandan Could you help me take a look?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix nth_value window function negates i64::MIN [datafusion]

Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey merged PR #22304:
URL: https://github.com/apache/datafusion/pull/22304


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org