perkolatte opened a new pull request, #71045:
URL: https://github.com/apache/doris/pull/71045

   ### Background
   
   The `time_zone` session variable sets the zone a session's time functions 
and conversions use. A new session starts on the FE's JVM default zone, which 
the read-only `system_time_zone` variable reports. `SET time_zone = ...` checks 
and standardizes the value in the FE before storing it, and every query sends 
the stored zone to the BEs that execute it. MySQL also accepts `SYSTEM`, 
meaning the server's system time zone.
   
   ### What problem does this PR solve?
   
   Issue Number: close #70809
   Related PR: None
   PR Type: Enhancement
   
   Problem Summary:
   
   Some MySQL clients, such as Tabularis, send `SET time_zone = 'SYSTEM'` while 
they set up a session, and Doris rejects it, so the connection fails. This PR 
accepts `SYSTEM` in any letter case for the session variable and resolves it 
when the `SET` runs, to the zone `@@system_time_zone` reports, which is also 
the zone a new session starts with. `SYSTEM` stays invalid everywhere else a 
time zone is accepted, such as `CONVERT_TZ`. Clients that never send `SYSTEM` 
see no change.
   
   ```sql
   SET time_zone = 'SYSTEM';
   ```
   
   | | Result |
   |---|---|
   | Before | `errCode = 2, detailMessage = Unknown or incorrect time zone: 
'SYSTEM'` |
   | After | Succeeds; `@@time_zone` is then the FE's system zone, the same as 
`@@system_time_zone` |
   
   ### Details
   
   - **Before and after:** Before, `SET [GLOBAL] time_zone = 'SYSTEM'` fails 
with the error above. After, it succeeds and stores the FE's system zone ID, 
for example `Asia/Shanghai`, so `SELECT @@time_zone` returns that ID, not the 
word `SYSTEM` as MySQL does.
   - **Configs and defaults:** None. No new config or variable, and the default 
of `time_zone` is unchanged.
   - **Impact on existing users:** None for SQL, data, or metadata that doesn't 
use `SYSTEM`. `SET GLOBAL time_zone = 'SYSTEM'` stores the zone of the FE that 
runs it, resolved once, rather than following each FE's OS zone afterwards.
   
   ### Testing
   
   - `VariableMgrTest#testSetTimeZoneSystem` (new): runs `SET time_zone = 
'SYSTEM'` and `'system'` through the FE and checks the session zone becomes the 
system zone. With `SetSessionVarOp` reverted to the old validator it fails with 
`Unknown or incorrect time zone: 'SYSTEM'`; with the change it passes.
   - `TimeUtilsTest` (two new cases): `SYSTEM` resolves to the system zone and 
equals a new session's default; other values still standardize or fail as 
before; `checkTimeZoneValidAndStandardize("SYSTEM")`, which `CONVERT_TZ` 
folding uses, still rejects it.
   - `TimeUtilsTest`, `TimeZoneParserTest` and `VariableMgrTest` all pass 
locally (36 tests, JDK 17, `TZ=Asia/Shanghai`; with the macOS default zone, the 
existing `testGetHourAsDate` fails on unrelated machine-zone grounds). These 
ran before a rebase onto `6261b18d`; none of the commits it brought in touch 
the changed files.
   - New regression suite 
`datatype_p0/datetimev2/test_set_time_zone_system.groovy` checks `@@time_zone` 
against `@@system_time_zone` after the `SET`, and that `CONVERT_TZ` gives the 
same result under `SYSTEM` as under the zone's name. Not run locally, because 
the BE does not build on macOS; it is in the default group, which P0 runs.
   
   ### Notes for Reviewers
   
   - `SYSTEM` is handled in a new 
`TimeUtils.checkSessionTimeZoneValidAndStandardize` rather than in 
`checkTimeZoneValidAndStandardize`, because the shared validator also checks 
`CONVERT_TZ` and `uuid_v7_to_datetime` arguments during FE constant folding, 
and the BE's `TimezoneUtils::find_cctz_time_zone` has no `SYSTEM`. Accepting it 
there would make folded and unfolded evaluation disagree, which 
`test_timezone_parser_contract` guards against. It would also let `SYSTEM` into 
persisted properties (routine load `timezone`, dynamic partition `time_zone`).
   - Resolving at `SET` time keeps a concrete zone in the session, so no reader 
of the session zone (coordinator, point queries, FE folding) has to resolve 
`SYSTEM`. The alternative is MySQL's model: store `SYSTEM`, return it from 
`@@time_zone`, and resolve it wherever the zone is sent to a BE. It matches 
MySQL readback exactly but touches every reader. I can switch to it if you 
prefer.
   - The `SET_VAR(time_zone = ...)` hint bypasses the time zone check entirely, 
as before; this PR does not change that.
   
   ### Release note
   
   `SET time_zone = 'SYSTEM'` is now accepted and sets the session to the FE's 
system time zone, the value of `@@system_time_zone`. `@@time_zone` then shows 
that zone's name rather than `SYSTEM`.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details)
   - Does this need documentation: Yes (a doris-website PR adding `SYSTEM` to 
the `time_zone` variable docs will follow once the behavior is agreed)
   - Pre-submission status: Partially verified: the new regression suite has 
not run; it needs a BE, which does not build on macOS, so CI P0 is its first run
   
   ### AI Disclosure
   
   - Tool: Claude Code (Claude Opus 5.5)
   - Generated: code, tests, this description
   - Human review: not stated
   - Prompts: The author picked #70809, chose to resolve `SYSTEM` at `SET` time 
to the FE system zone with the `@@time_zone` readback and `SET GLOBAL` 
trade-offs stated and MySQL's store-`SYSTEM` model offered as the alternative, 
then asked for it to be built and opened as a PR.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to