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

[PR] fix: lag i64::MIN offset overflow [datafusion]

chakkk309 opened a new pull request, #22338:
URL: https://github.com/apache/datafusion/pull/22338

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   - Closes #22223.
   
   ## Rationale for this change
   `lead` / `lag` normalize offsets internally by negating values in some cases. When the offset is `i64::MIN`, negating it overflows because `i64::MIN` cannot be represented as a positive `i64`.
   
   This can trigger an overflow panic instead of returning a proper DataFusion error.
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   This PR rejects `i64::MIN` offsets for `lead` / `lag` before they can be negated.
   
   It adds checked offset negation logic and returns an execution error like:
   
   ```text
   lag offset must not be i64::MIN
   ```
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Yes
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   Yes
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: lag i64::MIN offset overflow [datafusion]

Posted by "chakkk309 (via GitHub)" <gi...@apache.org>.
chakkk309 closed pull request #22338: fix: lag i64::MIN offset overflow
URL: https://github.com/apache/datafusion/pull/22338


-- 
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: lag i64::MIN offset overflow [datafusion]

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

   Closing this PR because the underlying panic has been fixed by #22243.
   
   I checked current main with the original reproducer from #22223:
   
   ```sql
   SELECT lag(x, -9223372036854775808) OVER (ORDER BY x)
   FROM (VALUES (1)) AS t(x);
   ```
   
   It no longer panics and now returns NULL. #22243 also added coverage for extreme lead/lag offsets, including i64::MIN.
   
   My PR returned an execution error for this case, while the merged fix treats the offset as out of range and returns the default value or NULL. Since the panic is already handled upstream, this PR is no longer needed.


-- 
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