Repository navigation
Cherry pick #100647 to 26.3: Fix session_timezone ignored during server-side DateTime parsing - #101351
Merged
Conversation
#100614 Co-Authored-By: Claude Opus 4.6 <[email protected]>
… the bug The bug affects all server-side parsing paths, not just async insert. HTTP sync inserts are also broken because `DataTypeDateTime` in table metadata bakes in the timezone at CREATE TABLE time. Compare unix timestamps to avoid the display-masking effect where wrong timezone on INSERT is cancelled out by the same wrong timezone on SELECT. Reference reflects current buggy behavior (3 of 4 cases wrong). Co-Authored-By: Claude Opus 4.6 <[email protected]>
…-side parsing
When a `DateTime` column has no explicit timezone, `SerializationDateTime`
used the timezone baked into table metadata (captured at CREATE TABLE time).
This caused `session_timezone` to be ignored for all server-side parsing
paths: async inserts over TCP, and both sync and async inserts over HTTP.
Add `getEffectiveTimeZone` that dynamically resolves the timezone via
`DateLUT::instance()` (which respects `session_timezone` from the current
thread's query context) when the column has no explicit timezone, and
returns the baked timezone when it does (e.g. `DateTime('UTC')`).
#100614
Co-Authored-By: Claude Opus 4.6 <[email protected]>
When session_timezone is active it should override the column's timezone
for text parsing, even for columns with an explicit timezone like
`DateTime('America/New_York')`. Updated `getEffectiveTimeZone` to check
whether `DateLUT::instance()` differs from the server default.
Extended the test to cover both `DateTime` (no explicit timezone) and
`DateTime('America/New_York')` (explicit timezone) cases.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Apply `session_timezone` fix to `SerializationDateTime64` (same pattern
as `SerializationDateTime`). Split `getEffectiveTimeZone` into
`getInputTimeZone` and `getOutputTimeZone`:
- Both respect explicit column timezone (e.g. `DateTime('UTC')`) — it
takes precedence over `session_timezone`.
- For columns without explicit timezone, both use `DateLUT::instance()`
which dynamically resolves `session_timezone`.
Extended the test to cover `DateTime64`, `DateTime64` with explicit
timezone, and `DateTime` with explicit timezone. Updated test
`02737_session_timezone` with section labels for easier debugging.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…etEffectiveTimeZone` Both methods had identical logic, so a single method is sufficient. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-authored-by: clickhouse-gh[bot] <173705893+clickhouse-gh[bot]@users.noreply.github.com>
The pooled serialization cache keys did not include the
`has_explicit_time_zone` flag. When two `DataType`s resolve to the same
timezone name but differ in whether the timezone was explicitly specified
(e.g. `DateTime('UTC')` vs plain `DateTime` on a UTC-default server),
they shared the same pooled `SerializationDateTime` object. With the
`getEffectiveTimeZone` change, `has_explicit_time_zone` now controls
whether the baked timezone or the dynamic `DateLUT::instance()` is used,
so the flag must be part of the cache key to avoid cross-contamination.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
…House/ClickHouse into test-async-insert-session-timezone
Co-authored-by: clickhouse-gh[bot] <173705893+clickhouse-gh[bot]@users.noreply.github.com>
…plicit timezone PR #100647 makes `SerializationDateTime` respect `session_timezone` via `DateLUT::instance()`, which is thread-context-dependent. Mutation background threads lack the original session context, so string literals like '2000-01-01 02:00:00' resolve to different Unix timestamps than intended. This adds an AST visitor that runs at ALTER time (alongside `replaceNonDeterministicToScalars`) and wraps DateTime string literals with explicit `toDateTime`/`toDateTime64` calls including the session timezone, making interpretation deterministic regardless of execution context. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…r-row The previous approach called `DateLUT::instance` in `getEffectiveTimeZone` on every row during serialization. Under parallel formatting with ASan, this caused extreme mutex contention in `DateLUT::getImplementation` (1M+ lock/unlock cycles per column), leading to timeouts in tests like `00159_parallel_formatting_http`. Move timezone resolution to `DataTypeDateTime::doGetSerialization` and `DataTypeDateTime64::doGetSerialization`, which are called once per column per chunk. The serialization object pool deduplicates by timezone hash, so only one instance exists per distinct timezone. The serialization objects remain immutable and safe for concurrent use. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…iter `getDateTimeColumnType` used `typeid_cast` directly on the column type, which missed wrapped variants like `Nullable(DateTime)` and `LowCardinality(DateTime)`. Unwrap via `removeNullable`/`removeLowCardinality` before the cast so mutation predicates on these columns are also rewritten with the session timezone. #100647 (comment) Co-Authored-By: Claude Opus 4.6 <[email protected]>
…timezone Fix session_timezone ignored during server-side DateTime parsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #100647
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job