[client-v2] QuerySettings.setUseTimeZone has no effect when the client uses the server time zone (the default)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 55/100
Rechercherichtung
Start with QuerySettings.java methods setUseTimeZone and setUseServerTimeZone, then trace how settings are merged and read in Client.buildRequestSettings and AbstractBinaryFormatReader.java. Check existing tests for query settings and DateTime decoding; add coverage for the reported default-client and explicit-column-time-zone cases. Done when per-query time zones reach the server and are used for decoding, while the listed override behaviors and docs are correct.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
On a client with the default use_server_time_zone=true, QuerySettings#setUseTimeZone(id) has no effect. DateTime / DateTime64 columns without an explicit time zone are still decoded in the server time zone. The setting is also not sent to the server. No error or warning is given.
The caller cannot turn the server time zone off on the same QuerySettings object: setUseServerTimeZone(false) and setUseTimeZone(..) throw Cannot set both use_time_zone and use_server_time_zone in either order. Only the raw setOption("use_server_time_zone", false) gets around the check.
The per-query setting works only when the client itself was built with useServerTimeZone(false) or useTimeZone(..).
Steps to reproduce
- Build a client with no time zone options (
use_server_time_zonedefaults totrue). The server time zone isUTC. - Run
SELECT toDateTime(0) AS twithnew QuerySettings().setUseTimeZone("Asia/Tokyo"). - Read
twithgetZonedDateTime("t")/getLocalDateTime("t"), or read it throughqueryAll.
Error Log or Exception StackTrace
No exception. Output of the code example below (server time zone UTC):
B default client, op setUseTimeZone(Tokyo) | zdt=1970-01-01T00:00Z[UTC] ldt=1970-01-01T00:00
C client.useTimeZone(Tokyo), no op time zone | zdt=1970-01-01T09:00+09:00[Asia/Tokyo] ldt=1970-01-01T09:00
D client useTimeZone(Berlin), op Tokyo | zdt=1970-01-01T09:00+09:00[Asia/Tokyo] ldt=1970-01-01T09:00
E default client, op Tokyo, DateTime64(3) | zdt=1970-01-01T00:00Z[UTC] ldt=1970-01-01T00:00
F default client, op Tokyo, DateTime('UTC') | zdt=1970-01-01T00:00Z[UTC] ldt=1970-01-01T00:00 (column time zone wins - correct)
G queryAll, default client, op Tokyo | zdt=1970-01-01T00:00Z[UTC]
H1 setUseServerTimeZone(false).setUseTimeZone(..) -> SettingsValidationException: Cannot set both use_time_zone and use_server_time_zone
H2 setUseTimeZone(..).setUseServerTimeZone(false) -> SettingsValidationException: Cannot set both use_time_zone and use_server_time_zone
H3 default client, op Tokyo + setOption("use_server_time_zone", false) | zdt=1970-01-01T09:00+09:00[Asia/Tokyo]
The setting does not reach the server either. Query SELECT timezone() AS tz, toString(toDateTime(0)) AS s, toDateTime(0) AS t on the default client:
op setUseTimeZone(Tokyo) | header tz=UTC server timezone()=UTC server toString=1970-01-01 00:00:00 client zdt=1970-01-01T00:00Z[UTC]
op setSessionTimezone(Tokyo) | header tz=Asia/Tokyo server timezone()=Asia/Tokyo server toString=1970-01-01 09:00:00 client zdt=1970-01-01T09:00+09:00[Asia/Tokyo]
Expected Behaviour
setUseTimeZone("Asia/Tokyo") on the operation gives 1970-01-01T09:00+09:00[Asia/Tokyo] for a DateTime column without a time zone. This is the result of a client built with Client.Builder#useTimeZone("Asia/Tokyo") (row C).
Evidence:
- The server interprets epoch 0 in
Asia/Tokyoas1970-01-01 09:00:00:
curl "http://<host>:8123/?session_timezone=Asia/Tokyo&query=SELECT+timezone(),+toString(toDateTime(0))"→Asia/Tokyo 1970-01-01 09:00:00. docs/clickhouse-docs/client.mdx:816documentsQuerySettings#setUseTimeZone(String timeZone)as "Requests server to usetimeZonefor time conversion. See session_timezone". Today it does neither: the server is not asked, and the client does not decode with it.Client.Builder#useTimeZone(Client.java:908-912) already setsuse_server_time_zone=false, because one option implies the other.
Root cause
QuerySettings.java:222-229:setUseTimeZonestores onlyuse_time_zoneon the operation. It does not setuse_server_time_zone=false, so the merged settings keep the client defaultuse_server_time_zone=true(ClientConfigProperties.java:55).AbstractBinaryFormatReader.java:82-85: whenuse_server_time_zone == TRUE, the reader usesquerySettings.getServerTimeZone()and never readsuse_time_zone.QuerySettings.java:210and:223: the mutual exclusion check useshasOption, not the value. SosetUseServerTimeZone(false)also blockssetUseTimeZone, and the reverse.
Also, the docs line for setUseServerTimeZone gives the default as false, but the code default is true.
The fix is in QuerySettings and in the two docs lines.
Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Code Example
Reproduction program (Java, 22 lines)
import com.clickhouse.client.api.Client;
import com.clickhouse.client.api.query.QueryResponse;
import com.clickhouse.client.api.query.QuerySettings;
import com.clickhouse.client.api.data_formats.ClickHouseBinaryFormatReader;
public class Repro {
public static void main(String[] a) throws Exception {
try (Client client = new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("")
.build()) { // default: use_server_time_zone=true
QuerySettings qs = new QuerySettings().setUseTimeZone("Asia/Tokyo");
try (QueryResponse r = client.query("SELECT toDateTime(0) AS t", qs).get();
ClickHouseBinaryFormatReader rd = client.newBinaryFormatReader(r)) {
rd.next();
// Expected: 1970-01-01T09:00+09:00[Asia/Tokyo]
// Actual: 1970-01-01T00:00Z[UTC] (server time zone)
System.out.println(rd.getZonedDateTime("t"));
}
}
}
}
Configuration
Client Configuration
new Client.Builder().addEndpoint("http://<host>:8123").setUsername("default").setPassword("...").build();
// no useServerTimeZone(..) / useTimeZone(..) / setServerTimeZone(..)
Environment
- Cloud
- Client version: client-v2
main@ 57261adf6 (0.12.0-rc1-SNAPSHOT) - Language version: Java 17 (Temurin 17.0.21)
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.10.4.207
- ClickHouse Server non-default settings, if any: none (server time zone
UTC) CREATE TABLEstatements for tables involved: none (SELECT toDateTime(0))- Sample data for all these tables: n/a
Found by automated analysis (Polyglot AI) while working on #3286. Verified against a live server. Shortened on 2026-11-20: the edit history has the first version.
- Vorherrschende Sprache
- Java
- Sterne
- 1.6k
- Forks
- 657
- Ø Merge
- 2 T. 6 Std.
- Gemergte PRs (30 T.)
- 36
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ClickHouse/clickhouse-java
-
api-diagnostics bug jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
ClickHouse/clickhouse-java#3464 ·
Maintainer antworten meist innerhalb von 1 Tag
-
tests
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3452 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc performance queries sql-parser
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
ClickHouse/clickhouse-java#3451 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug jdbc legacy queries
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
ClickHouse/clickhouse-java#3444 ·
Maintainer antworten meist innerhalb von 1 Tag
-
api-diagnostics bug client jdbc
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ClickHouse/clickhouse-java#3439 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in ClickHouse/clickhouse-java
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 60/100
quelea-projection/Quelea#749 ·
Maintainer antworten meist innerhalb von 1 Tag
-
free_port can hand one port to two callers, so the fixed-port http tests fail in parallel runsOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
erkamyaman/rust-anything#963 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 76/100
-
Deferred
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Sanne/incus-spawn#2768 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
morluto/rea#15041 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag