lazerg opened a new pull request, #71186:
URL: https://github.com/apache/doris/pull/71186
### Background
Nereids folds `repeat(str, n)` on the FE when both arguments are constants.
`StringArithmetic.repeat` only builds the string when the result is at most
1,000,000 characters. Above that it throws `AnalysisException`, and
`ExpressionEvaluator` keeps the call for the BE to run.
### What problem does this PR solve?
Issue Number: close #71181
Related PR: None
PR Type: Bugfix
Problem Summary:
The size check multiplies the string length by the count as `int`, so the
product can wrap below the limit. `repeat('ab', 1073741824)` gives -2147483648
and `repeat('%l', 2147483647)` gives -2, so the FE tries to build a string of
2^31 or more characters during planning and runs out of heap, which kills the
FE. The check now multiplies as `long`. The limit and the fallback stay the
same.
### Details
- **Frequency:** Always, for a constant `repeat` whose length times count
overflows `int`.
- **Root cause:** `first.getValue().length() * second.getValue()` is `int`
arithmetic.
- **Why existing tests missed it:** No test covered the `repeat` folding
guard.
- **Fix:** Cast the length to `long` before the multiplication.
- **Other paths and branches:** The same check is in branch-4.1 (reproduced
on 4.1.5 in the issue).
### Testing
- `StringArithmeticTest`: `testRepeatDoesNotFoldWhenSizeOverflowsInt` uses
the two values from the issue and fails before the fix.
`testRepeatFoldsUpToTheLimit` checks that 1,000,000 characters still fold and
one more repeat does not.
- I didn't build the FE locally; FE UT runs in CI.
### Release note
Fix an FE crash (out of memory) when a query folds a constant `repeat()`
whose result size overflows `int`.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Partially verified: FE UT not run locally
### AI Disclosure
- Tool: Claude Code (Claude Opus)
- Generated: the code change, the tests and this description
- Human review: reviewed the diff and the description
--
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]