rdtr opened a new pull request, #59194: URL: https://github.com/apache/spark/pull/59194
This replaces https://github.com/apache/spark/pull/56180, which was closed as stale. It addresses the review comments there: the merged limit is now folded with `ConstantFolding.constantFolding` as @asugranyes suggested, and the overflow case raised by @shrirangmhalgi is already rejected during analysis with `SUM_OF_LIMIT_AND_OFFSET_EXCEEDS_MAX_INT`. ### What changes were proposed in this pull request? `LimitPushDown` rewrites `LocalLimit(le, Offset(oe, child))` to `Offset(oe, LocalLimit(Add(le, oe), child))` and relies on a later `ConstantFolding` run to fold the `Add`. This PR folds the merged limit inside the rule with `ConstantFolding.constantFolding`: case LocalLimit(le, Offset(oe, grandChild)) => Offset(oe, LocalLimit(ConstantFolding.constantFolding(Add(le, oe)), grandChild)) This reuses the existing folding path, including its ANSI overflow behavior, and also folds foldable expressions that are not integer literals. ### Why are the changes needed? `BasicOperators` only plans `LocalLimit(IntegerLiteral, _)`. When `ConstantFolding` is excluded through `spark.sql.optimizer.excludedRules`, the unfolded `Add` reaches physical planning and fails with: java.lang.AssertionError: assertion failed: No plan for LocalLimit (1 + 2) ### Does this PR introduce _any_ user-facing change? No. With the default configuration, `ConstantFolding` folds the `Add` anyway. Only queries that failed when `ConstantFolding` was excluded now succeed. ### How was this patch tested? Added a test in `LimitPushdownSuite` that runs only `LimitPushDown` and checks that the merged limit is folded, for integer literals and for a foldable expression (`1 + 1`). The test fails without the change in `Optimizer.scala`. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code (Claude Opus 5.5) -- 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]
