HappenLee opened a new pull request, #67715:
URL: https://github.com/apache/doris/pull/67715
### What problem does this PR solve?
Issue Number: N/A
Related PR: N/A
Problem Summary:
Nereids rewrites `HOUR(CAST(FROM_UNIXTIME(ts) AS DATETIMEV2))` to
`hour_from_unixtime(ts)`, but the optimized function rejects valid timestamps
near the upper datetime boundary. For example, `ts = 253402243200` produces
`9999-12-31 08:00:00` in UTC and `9999-12-31 16:00:00` in Asia/Shanghai;
without the rewrite, HOUR returns 8 and 16 respectively, while the rewrite
fails with `INVALID_ARGUMENT`.
The BE helper uses a fixed conservative upper bound of `253402243199`.
The FE constant evaluators use an even smaller legacy bound. This change
computes the Unix timestamp corresponding to local `9999-12-31 23:59:59`
for the session time zone and aligns both implementations with that bound.
BE caches the bound in fragment-local function state during `open()` and
loads it once per block. The row loop retains its range check and field
extraction arithmetic; there are no additional per-row date conversions
or helper calls. The shared validation covers HOUR, MINUTE, SECOND, and
MICROSECOND. Invalid inputs still fail, with an updated range error.
Validation:
- FE `DateTimeExtractAndTransformTest`: 11 tests passed, including UTC,
Asia/Shanghai, negative/positive offsets, and boundary/invalid inputs.
- `./build.sh --fe -j 48`, including Checkstyle, passed.
- Modified C++ files passed clang-format 16, clang-tidy, and build hygiene.
- Added BE unit tests for timezone bounds and function execution. The BE
test build is blocked in unmodified `common/cpp/aws_common.cpp` because
the local shared AWS SDK lacks `GeneralHTTPCredentialsProvider.h`;
these tests have not run.
- Added regression tests comparing the rewrite with the original expression,
checking constant folding and rejecting the first invalid second. Both
changed Groovy suites passed syntax compilation; cluster execution has
not been performed.
- An isolated ordinary-input extraction-loop microbenchmark showed no
material regression (20 measured samples, alternating old/new runs,
fixed CPU affinity, thread CPU time). It excludes function initialization
and the complete execution framework and does not establish end-to-end
query performance.
### Release note
Fix optimized time field extraction rejecting valid FROM_UNIXTIME inputs
near the upper datetime boundary.
### Check List (For Author)
- Test
- [ ] Regression test
- [x] Unit Test
- [x] Manual test (format/static checks and isolated microbenchmark
described above)
- [ ] No need to test or manual test.
- Behavior changed:
- [ ] No.
- [x] Yes. Valid boundary timestamps now succeed using the session time
zone's upper bound.
- Does this need documentation?
- [x] No.
- [ ] Yes.
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label
--
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]