ninglinLiu opened a new pull request, #26674: URL: https://github.com/apache/datafusion/pull/26674
> [!IMPORTANT] > > **Fork CI setup:** For pull requests from a fork to `main`, enable workflows in your fork's **Actions** tab before you push. > See the [fork CI setup guide](https://datafusion.apache.org/contributor-guide/#pull-requests-from-forks). ## Which issue does this PR close? - Closes #26658. ## Rationale for this change A window frame with a huge `ROWS ... FOLLOWING` bound (e.g. `u64::MAX`) made `LimitPushPastWindows` panic in debug builds when growing `fetch` by `lookahead` (`fetch + ctx.lookahead`). In release builds the same addition wraps, so the `SortExec` TopK fetch can become smaller than the query needs. `EnsureRequirements` sort pushdown already uses `saturating_add` for the same kind of sum. Running the issue's reproduction also hit overflow in `calculate_range_rows` (`idx + n as usize + 1`), so the ROWS frame bound math is saturated the same way so the query can finish. ## What changes are included in this PR? - Use `saturating_add` in `LimitPushPastWindows` when combining fetch/lookahead/skip (and when accumulating lookahead). - Saturate ROWS `Following` start/end index arithmetic in `window_state::calculate_range_rows`. - Add a `window_limits.slt` case for the issue reproduction. ## What is the testing strategy for this PR? - New sqllogictest in `datafusion/sqllogictest/test_files/window_limits.slt` covering the issue query. - Locally: `cargo test --test sqllogictests -- window_limits`. ## Are there any user-facing changes? Bug fix only: queries with extremely large ROWS FOLLOWING bounds no longer panic in the optimizer / ROWS frame path. No API change. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
