morrySnow opened a new pull request, #67840:
URL: https://github.com/apache/doris/pull/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.
--
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]