Repository navigation
Conversation
|
Docs drift check: this PR looks like it needs doc updates.
|
With beta.row_binary_for_simple_insert=true, the RowBinary writer stored DateTime/DateTime64 values for columns without an explicit time zone as if their wall clock were UTC, while the text path and the reader use the server time zone. On a non-UTC server the same value was stored hours apart depending on the path. The writer now resolves the server time zone (ConnectionImpl caches it via loadServerInfo) and applies it to tz-less DateTime/DateTime64 columns, including nested in Array/Map/Tuple/Nullable. Backward-compatible: the existing writer constructor and every other serializer caller default to UTC. Fixes #3394 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
780e4dd to
42ba5fe
Compare
TriageCategory: Summary What this impacts
Concerns
Required reviewer action
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 42ba5fe. Configure here.
| // fall back to UTC below | ||
| } | ||
| tz = ZoneId.of(zoneId == null ? "UTC" : zoneId); | ||
| effectiveServerTimeZone = tz; |
There was a problem hiding this comment.
UTC timezone always reloads from server
Medium Severity
getEffectiveServerTimeZone treats any UTC value as “not yet loaded” and calls loadServerInfo, which overwrites the client’s server_time_zone with the live server zone. Explicit UTC cannot be pinned, use_time_zone is never consulted, and the documented workaround does not preserve the previous behaviour. Mutating shared client config also changes how later reads on the same connection decode DateTime.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 42ba5fe. Configure here.
| // fall back to UTC below | ||
| } | ||
| tz = ZoneId.of(zoneId == null ? "UTC" : zoneId); | ||
| effectiveServerTimeZone = tz; |
There was a problem hiding this comment.
Failed timezone lookup caches UTC forever
Medium Severity
When loadServerInfo fails, getEffectiveServerTimeZone swallows the exception and stores UTC in effectiveServerTimeZone for the connection lifetime. A transient error on the first writer statement then writes tz-less DateTime / DateTime64 values as UTC on a non-UTC server, recreating the mismatch this change is meant to fix.
Reviewed by Cursor Bugbot for commit 42ba5fe. Configure here.
AI review gate — Cursor Bugbot found issues
Unresolved findings (2):
What to do:
Re-run the gate with “Re-run jobs” after an approval or a finished review. A push re-runs it automatically. |
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
| // Default time zone for DateTime/DateTime64 columns that declare no zone of their own. | ||
| // The RowBinary writer sets it to the server time zone so stored values match the text path | ||
| // and the reader; it stays UTC for every other caller. See clickhouse-java#3394. | ||
| private static final ThreadLocal<ZoneId> WRITER_DEFAULT_TIME_ZONE = |
There was a problem hiding this comment.
This is very ugly way to make SerializerUtils (static by nature) as stateful class.
the biggest issue that this code doesn't enforce you to set correct timezone.
| this.tableSchema = tableSchema; | ||
| this.row = new Object[tableSchema.getColumns().size()]; | ||
| this.defaultSupport = format == ClickHouseFormat.RowBinaryWithDefaults; | ||
| this.defaultTimeZone = defaultTimeZone == null ? ZoneId.of("UTC") : defaultTimeZone; |
There was a problem hiding this comment.
we are trying to fix UTC and setting UTC in this place. This kind of wrong. It should all be aligned.


Summary
With
beta.row_binary_for_simple_insert=true, the RowBinary writer storedDateTime/DateTime64values for columns that have no explicit time zone as if their wall clock were UTC, while the default text path and the reader use the server time zone. On a non-UTC server the same value is stored hours apart depending on which path is used, with no error.Fixes #3394.
Behaviour change (semver note)
This changes stored values on the beta RowBinary writer path on non-UTC servers so they match the text path and the reader. The writer is behind the
beta.row_binary_for_simple_insertflag, so it is not yet a stable default. Anyone who relied on the previous UTC behaviour can pin the zone with the existinguse_time_zone/use_server_time_zonesettings.Fix
SerializerUtilsresolves the default zone for tz-lessDateTime/DateTime64columns from a writer-supplied zone (and keeps UTC for every other caller), set as scoped context aroundRowBinaryFormatWriter.commitRow.RowBinaryFormatWritertakes the server zone (backward-compatible constructor; the old one defaults to UTC).ConnectionImplresolves the server zone once vialoadServerInfoand caches it;WriterStatementImplpasses it to the writer.Testing
DateTime/DateTime64and an explicit-tzDateTime('Asia/Tokyo')column.DateTime,DateTime64, nestedArray/Tuple/Nullable/Map, and an explicit-tz column, with the JVM in both UTC and America/New_York, plus a UTC-server control. 154 assertions in each configuration, 0 failures. The writer now matches the text path and uses the server zone regardless of the JVM zone.🤖 Generated with Claude Code
Note
Medium Risk
Behaviour change for beta RowBinary inserts of tz-less DateTime types on non-UTC servers; limited to the flagged writer path but affects stored data semantics.
Overview
Fixes #3394: with
beta.row_binary_for_simple_insert, tz-lessDateTime/DateTime64columns were serialized as UTC in RowBinary while the text insert path and reader used the server zone, so the same JDBC values could land hours apart on non-UTC servers.RowBinary path:
RowBinaryFormatWriteraccepts adefaultTimeZone(existing 3-arg ctor still defaults to UTC). OncommitRow()it sets a scopedSerializerUtilsthread-local so tz-lessDateTime/DateTime64use that zone instead of hard-coded UTC; other callers keep UTC.JDBC wiring:
ConnectionImpl.getEffectiveServerTimeZone()resolves and caches the server zone (lazyloadServerInfowhen needed, UTC fallback).WriterStatementImplpasses it when creating the writer.Docs/tests: Changelog entry in
history/latest/3394.md. Integration test compares text vs RowBinary inserts forDateTime,DateTime64(3), andDateTime('Asia/Tokyo').Behaviour note: Stored timestamps on the beta RowBinary path change on non-UTC servers to align with text/reader; users who depended on UTC can use
use_time_zone/use_server_time_zone.Reviewed by Cursor Bugbot for commit 42ba5fe. Bugbot is set up for automated code reviews on this repo. Configure here.