Skip to content

Commit 736b4a6

Browse files
committed
Merge branch 'main' into clientv2_retries
2 parents e12c99f + 4fefbb9 commit 736b4a6

File tree

42 files changed

+1741
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1741
-199
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,20 @@ jobs:
5151
uses: actions/setup-java@v4
5252
with:
5353
distribution: "temurin"
54-
java-version: 8
54+
java-version: |
55+
8
56+
21
5557
cache: "maven"
5658
- name: Build and install libraries
5759
run: mvn --batch-mode --no-transfer-progress --show-version --strict-checksums --threads 2 -Dmaven.wagon.rto=30000 -DclickhouseVersion=$PREFERRED_LTS_VERSION -Dj8 install
5860
- name: Compile examples
5961
run: |
6062
export LIB_VER=$(grep '<revision>' pom.xml | sed -e 's|[[:space:]]*<[/]*revision>[[:space:]]*||g')
6163
find `pwd`/examples -type f -name pom.xml -exec sed -i -e "s|\(<clickhouse-java.version>\).*\(<\)|\1$LIB_VER\2|g" {} \;
62-
for d in $(ls -d `pwd`/examples/*/); do cd $d && mvn --batch-mode --no-transfer-progress clean compile; done
64+
for d in $(ls -d `pwd`/examples/*/); do \
65+
if [ -e $d/pom.xml ]; then cd $d && mvn --batch-mode --no-transfer-progress clean compile; fi;
66+
if [ -e $d/gradlew ]; then cd $d && ./gradlew clean build; fi;
67+
done
6368
- name: Upload test results
6469
uses: actions/upload-artifact@v4
6570
if: failure()
@@ -265,6 +270,7 @@ jobs:
265270
java-version: |
266271
8
267272
17
273+
21
268274
cache: "maven"
269275
- name: Setup Toolchain
270276
shell: bash

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
env:
1414
CHC_BRANCH: "main"
15-
CHC_VERSION: "0.6.3"
15+
CHC_VERSION: "0.6.4"
1616

1717
jobs:
1818
nightly:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
version:
77
description: "Release version"
88
required: true
9-
default: "0.6.3-SNAPSHOT"
9+
default: "0.6.4-SNAPSHOT"
1010

1111
jobs:
1212
release:

CHANGELOG.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,56 @@
11
## Latest
22

3+
## 0.6.4
4+
5+
### Deprecations
6+
- Following components will be deprecated and archived in next release:
7+
- clickhouse-cli-client
8+
- clickhouse-grpc-client
9+
- No more builds for non-lts Java versions - no more Java 9 release builds.
10+
- Lowest supported Java version will be 11.
11+
- Java 11 support will be ended before the end of 2023.
12+
- It is recommended to use Java 21.
13+
14+
### Important Changes
15+
- [Client-V1] Fix for handling DateTime without timezone when `session_timezone` is set. Now server timezone
16+
is parsed from server response when present (https://github.com/ClickHouse/clickhouse-java/issues/1464)
17+
18+
### New Features
19+
- [Client-V1/Apache HTTP] More configuration parameters for connection management. Useful for tuning performance.
20+
(https://github.com/ClickHouse/clickhouse-java/pull/1771)
21+
- com.clickhouse.client.config.ClickHouseClientOption#CONNECTION_TTL - to configure connection time-to-live
22+
- com.clickhouse.client.http.config.ClickHouseHttpOption#KEEP_ALIVE_TIMEOUT - to configure keep-alive timeout
23+
- com.clickhouse.client.http.config.ClickHouseHttpOption#CONNECTION_REUSE_STRATEGY - defines how connection pool behaves.
24+
If `FIFO` is selected then connections are reused in the order they were created. It results in even distribution of connections.
25+
If `LIFO` is selected then connections are reused as soon they are returned to the pool.
26+
Note: only for `APACHE_HTTP_CLIENT` connection provider.
27+
- Additionally switched to using LAX connection pool for Apache Connection Manager to improve performance
28+
for concurrent requests.
29+
- [Client-V2] Connection pool configuration https://github.com/ClickHouse/clickhouse-java/pull/1766
30+
- com.clickhouse.client.api.Client.Builder.setConnectionRequestTimeout - to configure connection request timeout.
31+
Important when there are no connections available in the pool to fail fast.
32+
- com.clickhouse.client.api.Client.Builder.setMaxConnections - configures how soft limit of connections per host.
33+
Note: Total number of connections is unlimited because in most cases there is one host.
34+
- com.clickhouse.client.api.Client.Builder.setConnectionTTL - to limit connection live ignoring keep-alive from server.
35+
- com.clickhouse.client.api.Client.Builder.setConnectionReuseStrategy - to configure how connections are used.
36+
Select FIFO to reuse connections evenly or LIFO (default) to reuse the most recently active connections.
37+
- [Client-V2] All operations are now executed in calling thread to avoid extra threads creation.
38+
Async operations can be enabled by `com.clickhouse.client.api.Client.Builder.useAsyncRequests` (https://github.com/ClickHouse/clickhouse-java/pull/1767)
39+
- [Client-V2] Content and HTTP native compression is supported now Currently only LZ4 is available. (https://github.com/ClickHouse/clickhouse-java/pull/1761)
40+
- [Client-V2] HTTPS support added. Required to communicate with ClickHouse Cloud Services.
41+
Client certificates are supported, too. (https://github.com/ClickHouse/clickhouse-java/pull/1753)
42+
- [Client-V2] Added support for HTTP proxy (https://github.com/ClickHouse/clickhouse-java/pull/1748)
43+
44+
### Documentation
45+
- [Client-V2] Spring Demo Service as usage example (https://github.com/ClickHouse/clickhouse-java/pull/1765)
46+
- [Client-V2] Examples for using text based formats (https://github.com/ClickHouse/clickhouse-java/pull/1752)
47+
48+
49+
### Bug Fixes
50+
- [Client-V2] Data is read fully from a stream. Important for Cloud instances (https://github.com/ClickHouse/clickhouse-java/pull/1759)
51+
- [Client-V2] Timezone from a server response is now used to parse DateTime values (https://github.com/ClickHouse/clickhouse-java/pull/1763)
52+
- [Client-V1] Timezone from a server response is now used to parse DateTime values (https://github.com/ClickHouse/clickhouse-java/issues/1464)
53+
354
## 0.6.3
455

556
### Important Changes

clickhouse-cli-client/src/test/java/com/clickhouse/client/cli/ClickHouseCommandLineClientTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.clickhouse.client.ClientIntegrationTest;
1111
import com.clickhouse.client.cli.config.ClickHouseCommandLineOption;
1212
import com.clickhouse.data.ClickHouseCompression;
13+
import com.clickhouse.data.ClickHouseFormat;
1314
import org.testcontainers.containers.GenericContainer;
1415
import org.testng.SkipException;
1516
import org.testng.annotations.BeforeClass;
@@ -199,4 +200,9 @@ public void testLoadBalancingPolicyFailover(ClickHouseLoadBalancingPolicy loadBa
199200
public void testFailover() {
200201
throw new SkipException("Skip due to failover is not supported");
201202
}
203+
204+
@Override
205+
public void testServerTimezoneAppliedFromHeader(ClickHouseFormat format) throws Exception {
206+
throw new SkipException("Skip due to session timezone is not supported");
207+
}
202208
}

clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseStreamResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import java.io.IOException;
44
import java.io.Serializable;
55
import java.util.Collections;
6+
import java.util.HashMap;
67
import java.util.List;
78
import java.util.Map;
89
import java.util.TimeZone;
910

11+
import com.clickhouse.client.config.ClickHouseClientOption;
12+
import com.clickhouse.config.ClickHouseOption;
1013
import com.clickhouse.data.ClickHouseColumn;
1114
import com.clickhouse.data.ClickHouseDataProcessor;
1215
import com.clickhouse.data.ClickHouseDataStreamFactory;
@@ -69,6 +72,11 @@ protected ClickHouseStreamResponse(ClickHouseConfig config, ClickHouseInputStrea
6972
this.timeZone = timeZone;
7073
boolean hasError = true;
7174
try {
75+
if (timeZone != null && config.isUseServerTimeZone() && !config.getUseTimeZone().equals(timeZone)) {
76+
Map<ClickHouseOption, Serializable> configOptions = new HashMap<>(config.getAllOptions());
77+
configOptions.put(ClickHouseClientOption.SERVER_TIME_ZONE, timeZone.getID());
78+
config = new ClickHouseConfig(configOptions);
79+
}
7280
this.processor = ClickHouseDataStreamFactory.getInstance().getProcessor(config, input, null, settings,
7381
columns);
7482
hasError = false;

clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseClientOption.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,16 @@ public enum ClickHouseClientOption implements ClickHouseOption {
425425
/**
426426
* Query ID to be attached to an operation
427427
*/
428-
QUERY_ID("query_id", "", "Query id");
428+
QUERY_ID("query_id", "", "Query id"),
429+
430+
431+
/**
432+
* Connection time to live in milliseconds. 0 or negative number means no limit.
433+
* Can be used to override keep-alive time suggested by a server.
434+
*/
435+
CONNECTION_TTL("connection_ttl", 0L,
436+
"Connection time to live in milliseconds. 0 or negative number means no limit."),
437+
;
429438

430439
private final String key;
431440
private final Serializable defaultValue;

clickhouse-client/src/test/java/com/clickhouse/client/ClientIntegrationTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
import java.nio.file.Files;
7171
import java.nio.file.Path;
7272
import java.nio.file.Paths;
73+
import java.time.Duration;
74+
import java.time.Instant;
75+
import java.time.LocalDateTime;
76+
import java.time.ZoneId;
77+
import java.time.ZoneOffset;
78+
import java.time.ZonedDateTime;
79+
import java.time.format.DateTimeFormatter;
7380
import java.util.ArrayList;
7481
import java.util.Collections;
7582
import java.util.HashMap;
@@ -2695,4 +2702,42 @@ public void testFailover() throws ClickHouseException {
26952702
Assert.assertEquals(response.firstRecord().getValue(0).asInteger(), 1);
26962703
}
26972704
}
2705+
2706+
@Test(groups = {"integration"}, dataProvider = "testServerTimezoneAppliedFromHeaderProvider")
2707+
public void testServerTimezoneAppliedFromHeader(ClickHouseFormat format) throws Exception {
2708+
System.out.println("Testing with " + format + " format");
2709+
ClickHouseNode server = getServer();
2710+
2711+
ZoneId custZoneId = ZoneId.of("America/Los_Angeles");
2712+
2713+
final String sql = "SELECT now(), toDateTime(now(), 'UTC') as utc_time, serverTimezone() SETTINGS session_timezone = 'America/Los_Angeles'";
2714+
try (ClickHouseClient client = getClient();
2715+
ClickHouseResponse response = newRequest(client, server)
2716+
.query(sql, UUID.randomUUID().toString())
2717+
.option(ClickHouseClientOption.FORMAT, format)
2718+
.executeAndWait()) {
2719+
2720+
Assert.assertEquals(response.getTimeZone().getID(), "America/Los_Angeles", "Timezone should be applied from the query settings");
2721+
2722+
ClickHouseRecord record = response.firstRecord();
2723+
final ZonedDateTime now = record.getValue(0).asZonedDateTime();
2724+
final ZonedDateTime utcTime = record.getValue(1).asZonedDateTime();
2725+
final String serverTimezone = record.getValue(2).asString();
2726+
Assert.assertNotEquals(serverTimezone, "America/Los_Angeles", "Server timezone should be applied from the query settings");
2727+
2728+
2729+
System.out.println("Now in America/Los_Angeles: " + now);
2730+
System.out.println("UTC Time: " + utcTime);
2731+
System.out.println("UTC Time: " + utcTime.withZoneSameInstant(custZoneId));
2732+
Assert.assertEquals(now, utcTime.withZoneSameInstant(custZoneId));
2733+
}
2734+
}
2735+
2736+
@DataProvider(name = "testServerTimezoneAppliedFromHeaderProvider")
2737+
public static ClickHouseFormat[] testServerTimezoneAppliedFromHeaderProvider() {
2738+
return new ClickHouseFormat[]{
2739+
ClickHouseFormat.TabSeparatedWithNamesAndTypes,
2740+
ClickHouseFormat.RowBinaryWithNamesAndTypes
2741+
};
2742+
}
26982743
}

clickhouse-grpc-client/src/main/java/com/clickhouse/client/grpc/ClickHouseGrpcResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void checkError(Result result) {
2929

3030
protected ClickHouseGrpcResponse(ClickHouseConfig config, Map<String, Serializable> settings,
3131
ClickHouseStreamObserver observer) throws IOException {
32-
super(config, observer.getInputStream(), settings, null, observer.getSummary(), null);
32+
super(config, observer.getInputStream(), settings, null, observer.getSummary(), observer.getTimeZone());
3333

3434
this.observer = observer;
3535
}

clickhouse-grpc-client/src/main/java/com/clickhouse/client/grpc/ClickHouseStreamObserver.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.io.UncheckedIOException;
5+
import java.util.TimeZone;
56
import java.util.concurrent.TimeUnit;
67
import java.util.concurrent.atomic.AtomicBoolean;
78
import java.util.concurrent.atomic.AtomicReference;
@@ -44,6 +45,8 @@ public class ClickHouseStreamObserver implements StreamObserver<Result> {
4445

4546
private final AtomicReference<IOException> errorRef;
4647

48+
private TimeZone timeZone;
49+
4750
protected ClickHouseStreamObserver(ClickHouseConfig config, ClickHouseNode server, ClickHouseOutputStream output) {
4851
this.server = server;
4952

@@ -128,6 +131,11 @@ protected boolean updateStatus(Result result) {
128131
}
129132
}
130133

134+
String tz = result.getTimeZone();
135+
if (!tz.isEmpty()) {
136+
timeZone = TimeZone.getTimeZone(result.getTimeZone());
137+
}
138+
131139
return proceed;
132140
}
133141

@@ -221,4 +229,8 @@ public boolean awaitCompletion(long timeout, TimeUnit unit) throws InterruptedEx
221229
public ClickHouseInputStream getInputStream() {
222230
return this.input;
223231
}
232+
233+
public TimeZone getTimeZone() {
234+
return timeZone;
235+
}
224236
}

0 commit comments

Comments
 (0)