branch-4.1: [fix](function) Align interval folding with runtime #67840 - #68174
Merged
Merged
Conversation
## Problem
`INTERVAL` could return different results for the same repeated
thresholds depending on whether the expression was constant-folded in
the frontend or evaluated by the backend.
For example, the folded expressions below returned `1, 2, 2`, while
equivalent expressions using a `numbers()` column returned `2, 3, 3`:
```sql
SELECT INTERVAL(0, 0, 0),
INTERVAL(0, 0, 0, 0),
INTERVAL(1, 0, 1, 1, 2);
```
## Root cause
Frontend constant folding used `Arrays.binarySearch`. When a sorted
threshold array contains duplicate values, Java may return any matching
position. Backend execution uses upper-bound semantics and continues
past all thresholds less than or equal to the comparison value.
## Fix
Replace frontend `binarySearch` with the same upper-bound binary-search
loop used by backend execution. Existing behavior for `NULL` comparison
values and `NULL` thresholds remains unchanged.
## Tests
- Added executable-function unit tests for repeated thresholds, empty
thresholds, lower/upper boundaries, and `NULL` values.
- Added regression coverage comparing frontend-folded expressions with
equivalent backend-evaluated expressions.
- Full frontend build and checkstyle passed.
- The focused unit test passed with 4 tests and no failures.
- The new regression suite passed.
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
|
skip buildall |
yiguolei
approved these changes
Sep 19, 2026
Contributor
Author
|
PR approved by anyone and no changes requested. |
Contributor
Author
|
PR approved by at least one committer and no changes requested. |
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 #67840