branch-4.0: [fix](simplify agg) SimplifyAggGroupBy should verify injectivity #64335#65108
Open
github-actions[bot] wants to merge 1 commit into
Open
branch-4.0: [fix](simplify agg) SimplifyAggGroupBy should verify injectivity #64335#65108github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
) ## Problem `SimplifyAggGroupBy` simplified `GROUP BY f(x)` to `GROUP BY x` without verifying that `f(x)` is injective (one-to-one). This caused wrong results: | Expression | Why wrong | |---|---| | `a * 0` / `0 * a` | always evaluates to 0 — all rows fall into one group | | `0 / a` | always evaluates to 0 | | `a / 0` | division by zero | | `a + NULL` / `a * NULL` / ... | always evaluates to NULL | | `a * 0.1` with float/double | precision loss may map different inputs to same result | ## Fix 1. **`isBinaryArithmeticSlot`**: restructured to separate slot-expr from literal, then validate each independently. Float/double check runs early, before slot extraction. 2. **New `checkLiteral(expr, literal)`**: rejects NULL literal and Multiply/Divide by zero. 3. **New `canExtractSlot(expr)`**: replaces the old unconditional `extractSlotOrCastOnSlot` — only accepts bare `Slot` or implicit lossless widening casts (integral→integral, float→double, integral→decimal, decimal→decimal). Range and scale are compared directly for correctness. ## Changes - `SimplifyAggGroupBy.java`: +80 lines, rewritten core logic - `ExpressionUtils.java`: -35 lines, removed unused `isSlotOrCastOnSlot` / `extractSlotOrCastOnSlot` - `SimplifyAggGroupByTest.java`: +216 lines, 25 tests covering all new paths --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
FE UT Coverage ReportIncrement line coverage |
Contributor
|
run p0 |
Contributor
|
run nonConcurrent |
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.
Cherry-picked from #64335