Forry-xrm opened a new pull request, #71072:
URL: https://github.com/apache/doris/pull/71072
### Background
Nereids folds constant expressions during analysis with
`FoldConstantRuleOnFE`: when a comparison has literal children on both sides,
it compares them through `ComparableLiteral#compareTo` and replaces the
expression with a boolean literal. Most literal types (`DateLiteral`,
`DateV2Literal`, `BooleanLiteral`, ...) implement `ComparableLiteral`;
`TimeV2Literal`, which holds a TIMEV2 value as `[-838:59:59, 838:59:59]`, did
not.
### What problem does this PR solve?
Issue Number: close #70635
Related PR: None
PR Type: Bugfix
Problem Summary: A range comparison between two TIME constants fails during
planning with `TimeV2Literal cannot be cast to ComparableLiteral`, so such
queries never run. The fix makes `TimeV2Literal` comparable, using the signed
microsecond value that BE also uses for TIMEV2. The diff is small and mostly
tests.
### Details
- **Frequency:** Any statement whose plan contains a comparison of two TIME
literals; the failure is deterministic and happens at analysis time, before
execution.
- **Root cause:** `TimeV2Literal` extends `Literal` only.
`FoldConstantRuleOnFE` casts the operands to `ComparableLiteral` before calling
`compareTo`, so folding a TIME-vs-TIME comparison threw `ClassCastException`.
- **Why existing tests missed it:** `TimeV2LiteralTest` covered parsing,
arithmetic and string conversion but never a comparison, and no
`FoldConstantTest` case used TIME literals.
- **Fix:** `TimeV2Literal` now implements `ComparableLiteral`, comparing
signed microseconds via a new `getMicroSecondValue()` that `getValue()` also
reuses (same value as before). `NullLiteral` and `MaxLiteral` are handled like
in the other literals; other types raise the same "Cannot compare two values
with different data types" error as `DateLiteral`.
- **Other paths and branches:** The same comparison path serves `<`, `<=`,
`>`, `>=`, `=` and `!=` on TIME literals; all of them go through this
`compareTo` after the change.
### Testing
Ran on an x86_64 build host, offline Maven build of the FE reactor:
```
mvn -o -B -pl fe-core -am -Dtest=TimeV2LiteralTest,FoldConstantTest \
-DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false
surefire:test
```
`Tests run: 42, Failures: 0, Errors: 0` (`TimeV2LiteralTest` 11,
`FoldConstantTest` 31). `testFoldTimeCompare` fails with the
`ClassCastException` before the fix and passes after it.
### Notes for Reviewers
- `getValue()` keeps returning a `double`, now built from
`getMicroSecondValue()`, so the negative-time handling lives in one place.
- Negative times compare as negative microseconds, so `-00:00:01 < 00:00:00`
and `time'838:59:59'` stays the maximum, consistent with BE's numeric
comparison of TIMEV2.
### Release note
Queries that compare two TIME constants, for example `time'10:15:30' <
time'11:00:00'`, now plan and return results instead of failing with a
`ClassCastException` during analysis.
### Check List (For Author)
- Behavior changed: No
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: CodeBuddy (DeepSeek V4.1 Flash)
- Generated: the code change, the unit tests and this description were
produced with the agent and edited by the author.
- Human review: the author reviewed the diff, and the build and tests above
were run against that diff.
--
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]