Skip to content

Commit e9ef623

Browse files
committed
fixed passing timezone from old client
1 parent fae09e1 commit e9ef623

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,11 @@ private Map<String, String> setDefaults(Map<String, String> userConfig) {
632632
}
633633

634634
if (!userConfig.containsKey(ClickHouseClientOption.USE_SERVER_TIME_ZONE.getKey())) {
635-
userConfig.put(ClickHouseClientOption.USE_SERVER_TIME_ZONE.getKey(),
636-
String.valueOf(ClickHouseClientOption.USE_SERVER_TIME_ZONE.getDefaultValue()));
635+
userConfig.put(ClickHouseClientOption.USE_SERVER_TIME_ZONE.getKey(), "true");
636+
}
637+
638+
if (!userConfig.containsKey(ClickHouseClientOption.SERVER_TIME_ZONE.getKey())) {
639+
userConfig.put(ClickHouseClientOption.SERVER_TIME_ZONE.getKey(), "UTC");
637640
}
638641

639642
return userConfig;
@@ -1086,9 +1089,9 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
10861089
}
10871090
ClientStatisticsHolder clientStats = new ClientStatisticsHolder();
10881091
clientStats.start(ClientMetrics.OP_DURATION);
1092+
applyDefaults(settings);
10891093

10901094
if (useNewImplementation) {
1091-
applyDefaults(settings);
10921095
//
10931096
String retry = configuration.get(ClickHouseClientOption.RETRY.getKey());
10941097
final int maxRetries = retry == null ? (int) ClickHouseClientOption.RETRY.getDefaultValue() : Integer.parseInt(retry);
@@ -1222,7 +1225,7 @@ public List<GenericRecord> queryAll(String sqlQuery) {
12221225
List<GenericRecord> records = new ArrayList<>();
12231226
if (response.getResultRows() > 0) {
12241227
ClickHouseBinaryFormatReader reader =
1225-
new RowBinaryWithNamesAndTypesFormatReader(response.getInputStream(), settings);
1228+
new RowBinaryWithNamesAndTypesFormatReader(response.getInputStream(), response.getSettings());
12261229
Map<String, Object> record;
12271230
while ((record = reader.next()) != null) {
12281231
records.add(new MapBackedRecord(record, reader.getSchema()));
@@ -1332,6 +1335,11 @@ private void applyDefaults(QuerySettings settings) {
13321335
if ( !settings.getUseServerTimeZone() && !settingsMap.containsKey(key) && configuration.containsKey(key)) {
13331336
settings.setOption(key, TimeZone.getTimeZone(configuration.get(key)));
13341337
}
1338+
1339+
key = ClickHouseClientOption.SERVER_TIME_ZONE.getKey();
1340+
if (!settingsMap.containsKey(key) && configuration.containsKey(key)) {
1341+
settings.setOption(key, TimeZone.getTimeZone(configuration.get(key)));
1342+
}
13351343
}
13361344

13371345
public String toString() {

client-v2/src/test/java/com/clickhouse/client/insert/InsertTests.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@ public void testNoHttpResponseFailure() {
152152
byte[] requestBody = ("INSERT INTO table01 FORMAT " +
153153
ClickHouseFormat.TSV.name() + " \n1\t2\t3\n").getBytes();
154154

155+
// First request gets no response
155156
faultyServer.addStubMapping(WireMock.post(WireMock.anyUrl())
156157
.withRequestBody(WireMock.binaryEqualTo(requestBody))
157158
.inScenario("Retry")
158159
.whenScenarioStateIs(STARTED)
159160
.willSetStateTo("Failed")
160161
.willReturn(WireMock.aResponse().withFault(Fault.EMPTY_RESPONSE)).build());
161162

163+
// Second request gets a response (retry)
162164
faultyServer.addStubMapping(WireMock.post(WireMock.anyUrl())
163165
.withRequestBody(WireMock.binaryEqualTo(requestBody))
164166
.inScenario("Retry")
@@ -177,19 +179,7 @@ public void testNoHttpResponseFailure() {
177179
.compressClientRequest(false)
178180
.setOption(ClickHouseClientOption.RETRY.getKey(), "2")
179181
.build();
180-
Runnable powerBlink = () -> {
181-
try {
182-
Thread.sleep(100);
183-
faultyServer.stop();
184-
Thread.sleep(50);
185-
faultyServer.start();
186-
} catch (InterruptedException e) {
187-
Assert.fail("Unexpected exception", e);
188-
}
189-
};
190182
try {
191-
new Thread(powerBlink).start();
192-
Thread.sleep(200);
193183
InsertResponse insertResponse = mockServerClient.insert("table01",
194184
new ByteArrayInputStream("1\t2\t3\n".getBytes()), ClickHouseFormat.TSV, settings).get(30, TimeUnit.SECONDS);
195185
insertResponse.close();

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,7 @@ public void testClientUseOwnTimeZone() {
12271227
ZonedDateTime serverUtcTimeZ = serverUtcTime.atZone(ZoneId.of("UTC"));
12281228

12291229
Assert.assertEquals(serverTimeZ.withZoneSameInstant(ZoneId.of("UTC")), serverUtcTimeZ);
1230-
Assert.assertEquals(serverLisbonTime.withZoneSameInstant(ZoneId.of("UTC")), serverTimeZ);
1230+
Assert.assertEquals(serverLisbonTime.withZoneSameInstant(ZoneId.of("UTC")), serverUtcTimeZ);
12311231
}
12321232
} catch (Exception e) {
12331233
e.printStackTrace();

0 commit comments

Comments
 (0)