POSSIBLEwbwb opened a new pull request, #66860:
URL: https://github.com/apache/doris/pull/66860
# [feature](function) Add Trino-compatible timezone_hour and timezone_minute
functions
Issue: #48203
## Purpose
Add two new scalar functions `timezone_hour(timestamp_tz)` and
`timezone_minute(timestamp_tz)`
for Trino compatibility. They return the hour / minute component of the
timezone offset
of the session timezone at the given instant (DST-aware), consistent with
Trino semantics:
- `timezone_hour(timestamp '2024-01-01 00:00:00+08:00')` -> `8`
- `timezone_hour(timestamp '2024-07-01 00:00:00+00:00')` with session tz
`America/New_York` -> `-4`
- `timezone_minute(timestamp '2024-01-01 00:00:00-04:30')` -> `-30`
## Changes
### BE
- `be/src/exprs/function/function_timezone_hour_minute.cpp` (new)
- `FunctionTimezoneHour` / `FunctionTimezoneMinute`: read
`context->state()->timezone_obj()`,
compute offset via `TimestampTzValue::utc_offset()` (DST-aware), return
`offset / 3600` / `(offset % 3600) / 60` as Int64.
- `be/src/exprs/function/simple_function_factory.h`
- register both functions.
### FE
-
`fe/fe-core/.../nereids/trees/expressions/functions/scalar/TimezoneHour.java`
(new)
-
`fe/fe-core/.../nereids/trees/expressions/functions/scalar/TimezoneMinute.java`
(new)
- UnaryExpression, `ExplicitlyCastableSignature`, signature `BIGINT <-
TIMESTAMP_TZ(WILDCARD)`,
`PropagateNullable` (same pattern as TimeToSec).
-
`fe/fe-core/.../nereids/trees/expressions/visitor/ScalarFunctionVisitor.java`
- visit methods.
- `fe/fe-core/.../catalog/BuiltinScalarFunctions.java`
- registration of `timezone_hour` / `timezone_minute`.
### Regression
- `pytest/qe/palo2/src/test_query_datetime_function.py`
- `test_query_timezone_hour_minute`: fixed-offset (Asia/Shanghai),
DST (America/New_York), fractional offsets (-04:30, +05:45), nullable
input.
## Test plan
- [x] `mvn package -DskipTests -Dskip.doc=true -T 4 -pl fe-core -am` — BUILD
SUCCESS, checkstyle clean
- [x] BE unit test `function_timezone_hour_minute_test` (fixed offset / DST
/ fractional / nullable)
- [x] pytest regression `test_query_datetime_function.py`
## License
This contribution is licensed under the Apache License 2.0.
--
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]