[fix](function) Align interval folding with runtime - #67840
Merged
morrySnow merged 1 commit intoSep 14, 2026
Merged
Conversation
Problem: INTERVAL returned different results for repeated thresholds depending on whether the expression was folded in the frontend or executed in the backend. Cause: Java binarySearch may return any matching duplicate, while backend execution uses upper-bound semantics and counts every threshold less than or equal to the comparison value. Solution: Replace binarySearch with the same upper-bound loop used by backend execution, including existing NULL threshold behavior. Tests: Added focused executable-function unit coverage and regression coverage comparing folded and runtime expressions across duplicates, NULLs, and boundaries.
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 11, 2026 05:07
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
TPC-H: Total hot run time: 16715 ms |
Contributor
TPC-DS: Total hot run time: 81129 ms |
Contributor
ClickBench: Total hot run time: 14.61 s |
starocean999
approved these changes
Sep 12, 2026
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.
Problem
INTERVALcould 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 anumbers()column returned2, 3, 3: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
binarySearchwith the same upper-bound binary-search loop used by backend execution. Existing behavior forNULLcomparison values andNULLthresholds remains unchanged.Tests
NULLvalues.