Skip to content

branch-4.1: [fix](function) Align interval folding with runtime #67840 - #68174

Merged
yiguolei merged 1 commit into
branch-4.1from
auto-pick-67840-branch-4.1
Sep 19, 2026
Merged

yiguolei merged 1 commit into
branch-4.1from
auto-pick-67840-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #67840

## 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.
@github-actions
github-actions Bot requested a review from yiguolei as a code owner September 18, 2026 08:18
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 100.00% (8/8) 🎉
Increment coverage report
Complete coverage report

@yiguolei

Copy link
Copy Markdown
Contributor

skip buildall

@yiguolei
yiguolei merged commit b98482d into branch-4.1 Sep 19, 2026
38 of 39 checks passed
@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by anyone and no changes requested.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Sep 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by at least one committer and no changes requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants