Skip to content

Commit 20ed16b

Browse files
committed
Merge branch 'main' into jdbc_fix_date_problem
2 parents 3a9ff80 + f9f588d commit 20ed16b

File tree

39 files changed

+1060
-377
lines changed

39 files changed

+1060
-377
lines changed

.github/workflows/test_head.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Test with CH HEAD
2+
3+
on:
4+
schedule:
5+
- cron: "55 10 * * *"
6+
push:
7+
branches:
8+
- main
9+
paths-ignore:
10+
- "**.md"
11+
- "**/docs/**"
12+
- "**/LICENSE"
13+
- "**/NOTICE"
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.event.number || github.sha }}
17+
cancel-in-progress: true
18+
19+
env:
20+
CH_VERSION: "head"
21+
22+
jobs:
23+
test-java-client:
24+
runs-on: ubuntu-latest
25+
strategy:
26+
matrix:
27+
project: ["clickhouse-http-client", "client-v2", "clickhouse-jdbc"]
28+
fail-fast: false
29+
timeout-minutes: 15
30+
name: ${{ matrix.project }}
31+
steps:
32+
- uses: actions/checkout@v5
33+
- name: Set up JDK
34+
uses: actions/setup-java@v4
35+
with:
36+
java-version: '17'
37+
distribution: 'temurin'
38+
architecture: x64
39+
- name: Test Java client
40+
run: |
41+
mvn --also-make --batch-mode --no-transfer-progress --projects ${{ matrix.project }} -DclickhouseVersion=$CH_VERSION -Dmaven.javadoc.skip=true clean install
42+
- name: Upload test results
43+
uses: actions/upload-artifact@v4
44+
if: failure()
45+
with:
46+
name: result ${{ github.job }}_${{ matrix.project }}
47+
path: |
48+
**/target/failsafe-reports
49+
**/target/surefire-reports
50+
retention-days: 5
51+
52+
test-r2dbc-driver:
53+
runs-on: ubuntu-latest
54+
strategy:
55+
matrix:
56+
protocol: ["http"]
57+
r2dbc: ["1.0.0.RELEASE", "0.9.1.RELEASE"]
58+
fail-fast: false
59+
timeout-minutes: 10
60+
name: R2DBC ${{ matrix.r2dbc }} + CH HEAD (${{ matrix.protocol }})
61+
steps:
62+
- uses: actions/checkout@v5
63+
- name: Set up JDK
64+
uses: actions/setup-java@v4
65+
with:
66+
java-version: '17'
67+
distribution: 'temurin'
68+
architecture: x64
69+
- name: Test R2DBC ${{ matrix.r2dbc }}
70+
run: |
71+
mvn --batch-mode --no-transfer-progress --projects clickhouse-r2dbc -DclickhouseVersion=$CH_VERSION \
72+
-D'r2dbc-spi.version=${{ matrix.r2dbc }}' -Dprotocol=${{ matrix.protocol }} -Dmaven.javadoc.skip=true clean install
73+
- name: Upload test results
74+
uses: actions/upload-artifact@v4
75+
if: failure()
76+
with:
77+
name: result ${{ github.job }}_${{ matrix.r2dbc }}_${{ matrix.protocol }}
78+
path: |
79+
**/target/failsafe-reports
80+
**/target/surefire-reports

CHANGELOG.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
1+
## 0.9.5
2+
3+
### New Features
4+
- [client-v2] Log durations in ISO-8601 duration format
5+
6+
## 0.9.4
7+
8+
### New Features
9+
- [client-v2] Added support for different compression algorithms when HTTP compression is enabled. (https://github.com/ClickHouse/clickhouse-java/pull/2645)
10+
11+
### Bug Fixes
12+
- [client-v1] Fixes issue linked to a enabled by default HTTP compression in ClickHouse 25.10. (https://github.com/ClickHouse/clickhouse-java/issues/2636)
13+
14+
## 0.9.3
15+
16+
### Important Changes
17+
- [jdbc-v2] SQL parser from v1 is ported to v2 to address multiple issues with SQL parsing. The ANTLR4-based parser is
18+
still an option and will be developed further. The main difference between parses is completeness of their grammar:
19+
JavaCC grabs only needed information and skips parsing of the rest (what makes it work for most cases) while ANTLR4
20+
has more complete grammar and can detect type of some complex statements more accurate than JavaCC.
21+
To use it set `com.clickhouse.jdbc.DriverProperties#SQL_PARSER` to `ANTLR4`.
22+
(https://github.com/ClickHouse/clickhouse-java/pull/2579). This fixes issue:
23+
- https://github.com/ClickHouse/clickhouse-java/issues/2574
24+
- https://github.com/ClickHouse/clickhouse-java/issues/2568
25+
- https://github.com/ClickHouse/clickhouse-java/issues/2537
26+
- https://github.com/ClickHouse/clickhouse-java/issues/2595
27+
- https://github.com/ClickHouse/clickhouse-java/issues/2617
28+
- https://github.com/ClickHouse/clickhouse-java/issues/2569
29+
- https://github.com/ClickHouse/clickhouse-java/issues/2570
30+
- https://github.com/ClickHouse/clickhouse-java/issues/2571
31+
- https://github.com/ClickHouse/clickhouse-java/issues/2572
32+
- https://github.com/ClickHouse/clickhouse-java/issues/2573
33+
- https://github.com/ClickHouse/clickhouse-java/issues/2609
34+
- https://github.com/ClickHouse/clickhouse-java/issues/2527
35+
36+
- [repo] New artifact `clickhouse-jdbc-all` added to address issue when maven package qualifiers may not be used.
37+
This artifact should is a copy of `clickhouse-jdbc:all` but should be used only when required. (https://github.com/ClickHouse/clickhouse-java/issues/2625)
38+
39+
### Improvements
40+
- [client-v2] Added `getShortArray()` and `getStringArray()` to `ClickHouseBinaryFormatReader`. (https://github.com/ClickHouse/clickhouse-java/pull/2604)
41+
- [client-v2] Added `result_rows` and `elapsed_time` to summary object. (https://github.com/ClickHouse/clickhouse-java/pull/1633/files)
42+
43+
### Bug Fixes
44+
- [jdbc-v2] Fixed issue with `maxRows` in `Statement` when additional settings were used to limit result set size.
45+
It caused problems with read-only users because such users may not change settings in most cases. Now when `maxRows` is
46+
set then `ResultSet` will skip extra rows. (https://github.com/ClickHouse/clickhouse-java/issues/2582)
47+
- [jdbc-v2] Fixed issue with driver version. Previously version of a library was converted to minor and major version.
48+
But this approach doesn't work well with `0.9.x` versions. Now major and minor versions are combined by shifting major.
49+
Patch version becomes a minor version. (https://github.com/ClickHouse/clickhouse-java/issues/2410)
50+
- [jdbc-v2, client-v2] Fixed converting different data types to a string. For example, there was an issue with IP
51+
address when `toString()` was used and returned `\0.0.0.0` instead of `0.0.0.0`. (https://github.com/ClickHouse/clickhouse-java/issues/2575)
52+
- [jdbc-v2] Fixed issues around spatial data (GEO types). (https://github.com/ClickHouse/clickhouse-java/issues/2577)
53+
- [client-v2] Fixed issue with current user name. If user name is set then it will be used event after reading
54+
server context. (https://github.com/ClickHouse/clickhouse-java/issues/2247)
55+
- [client-v2] Fixed issue with network timeout settings when default value failed to be cast to Long. (https://github.com/ClickHouse/clickhouse-java/issues/2597)
56+
- [jdbc-v2] Fixed getting metadata for nullable columns. (https://github.com/ClickHouse/clickhouse-java/issues/2586)
57+
- [jdbc-v2, client-v2] Fixed issues related to reading JSON data type. Fixed reading JSON columns with arrays. Previously was causing exceptions like
58+
`com.clickhouse.client.api.ClientException: Unsupported data type with tag 101 at ...`
59+
(https://github.com/ClickHouse/clickhouse-java/issues/2598, https://github.com/ClickHouse/clickhouse-java/issues/2593,
60+
https://github.com/ClickHouse/clickhouse-java/issues/2613, https://github.com/ClickHouse/clickhouse-java/issues/2102)
61+
- [client-v2] Fixed configuration parameter type for `socket_linger` to match documentation. (https://github.com/ClickHouse/clickhouse-java/issues/2524)
62+
- [client-v2] Fixed handling exceptions in http client code. Now response object is always closed to prevent connection leaking. (https://github.com/ClickHouse/clickhouse-java/pull/2615)
63+
- [jdbc-v2, client-v2] Fixed issue with duplicate column names in a result set. (https://github.com/ClickHouse/clickhouse-java/issues/2459, https://github.com/ClickHouse/clickhouse-java/issues/2336)
64+
- [jdbc-v2] Fixed ANTLR4 parse issue with `filter` clause along with aggregate function. (https://github.com/ClickHouse/clickhouse-java/pull/2631)
65+
166
## 0.9.2
267

368
### Improvements

clickhouse-client/src/test/resources/containers/clickhouse-server/users.d/users.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@
6262
</poorman2>
6363
<test>
6464
<profile>default</profile>
65-
<networks incl="networks" replace="replace">
66-
<ip>::/0</ip>
67-
</networks>
65+
<!-- <networks incl="networks" replace="replace">-->
66+
<!-- <ip>::/0</ip>-->
67+
<!-- </networks>-->
6868
<password>123</password>
6969
<quota>default</quota>
7070
<allow_databases>
@@ -78,9 +78,9 @@
7878
</me>
7979
<access_dba>
8080
<profile>default</profile>
81-
<networks incl="networks" replace="replace">
82-
<ip>::/0</ip>
83-
</networks>
81+
<!-- <networks incl="networks" replace="replace">-->
82+
<!-- <ip>::/0</ip>-->
83+
<!-- </networks>-->
8484
<password>123</password>
8585
<quota>default</quota>
8686
<access_management>1</access_management>

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ public enum ClickHouseDataType implements SQLType {
128128
AggregateFunction(String.class, true, true, false, 0, 0, 0, 0, 0, true),
129129
Variant(List.class, true, true, false, 0, 0, 0, 0, 0, true, 0x2A),
130130
Dynamic(Object.class, true, true, false, 0, 0, 0, 0, 0, true, 0x2B),
131-
Time(LocalDateTime.class, false, false, false, 4, 9, 0, 0, 9, false, 0x32),
132-
Time64(LocalDateTime.class, true, false, false, 8, 9, 0, 0, 0, false, 0x34),
131+
Time(LocalDateTime.class, true, false, false, 4, 9, 0, 0, 9, false, 0x32), // 0x33 for Time(Timezone)
132+
Time64(LocalDateTime.class, true, false, false, 8, 9, 0, 0, 0, false, 0x34), // 0x35 for Time64(P, Timezone)
133+
QBit(Double.class, true, true, false, 0, 0, 0, 0, 0, false, 0x36),
133134
;
134135

135136
public static final List<ClickHouseDataType> ORDERED_BY_RANGE_INT_TYPES =

clickhouse-data/src/test/java/com/clickhouse/data/ClickHouseColumnTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ public boolean isWidenUnsignedTypes() {
423423
if (type.isNested() || type == ClickHouseDataType.AggregateFunction
424424
|| type == ClickHouseDataType.SimpleAggregateFunction || type == ClickHouseDataType.Enum
425425
|| type == ClickHouseDataType.Nullable || type == ClickHouseDataType.BFloat16 ||
426-
type == ClickHouseDataType.Time || type == ClickHouseDataType.Time64) {
426+
type == ClickHouseDataType.Time || type == ClickHouseDataType.Time64 || type == ClickHouseDataType.QBit) {
427427
continue;
428428
}
429429

clickhouse-http-client/src/main/java/com/clickhouse/client/http/ClickHouseHttpConnection.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,10 @@ protected static Map<String, String> createDefaultHeaders(ClickHouseConfig confi
275275
}
276276
// Also, you can use the ‘default_format’ URL parameter
277277
map.put("x-clickhouse-format", config.getFormat().name());
278-
if (config.isResponseCompressed()) {
278+
if (config.isResponseCompressed() && config.getResponseCompressAlgorithm() != ClickHouseCompression.LZ4) {
279279
map.put("accept-encoding", config.getResponseCompressAlgorithm().encoding());
280280
}
281-
if (config.isRequestCompressed()
282-
&& config.getRequestCompressAlgorithm() != ClickHouseCompression.LZ4) {
281+
if (config.isRequestCompressed() && config.getRequestCompressAlgorithm() != ClickHouseCompression.LZ4) {
283282
map.put("content-encoding", config.getRequestCompressAlgorithm().encoding());
284283
}
285284
return map;

clickhouse-jdbc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0"
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>

client-v2/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
<version>5.19.0</version>
142142
<scope>test</scope>
143143
</dependency>
144+
<dependency>
145+
<groupId>com.github.luben</groupId>
146+
<artifactId>zstd-jni</artifactId>
147+
<version>1.5.7-6</version>
148+
<scope>test</scope>
149+
</dependency>
144150
</dependencies>
145151

146152
<build>

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public boolean ping(long timeout) {
11321132
return true;
11331133
}
11341134
} catch (Exception e) {
1135-
LOG.debug("Failed to connect to the server (Duration: {})", System.nanoTime() - startTime, e);
1135+
LOG.debug("Failed to connect to the server (Duration: {})", durationSince(startTime), e);
11361136
return false;
11371137
}
11381138
}
@@ -1277,7 +1277,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
12771277

12781278
// Check response
12791279
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1280-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), System.nanoTime() - startTime);
1280+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
12811281
selectedEndpoint = getNextAliveNode();
12821282
continue;
12831283
}
@@ -1292,7 +1292,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
12921292
return new InsertResponse(metrics);
12931293
} catch (Exception e) {
12941294
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
1295-
(i + 1), (maxRetries + 1), System.nanoTime() - startTime), e);
1295+
(i + 1), (maxRetries + 1), durationSince(startTime)), e);
12961296
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
12971297
LOG.warn("Retrying.", e);
12981298
selectedEndpoint = getNextAliveNode();
@@ -1301,7 +1301,7 @@ public CompletableFuture<InsertResponse> insert(String tableName, List<?> data,
13011301
}
13021302
}
13031303
}
1304-
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + (System.nanoTime() - startTime), lastException);
1304+
throw new ClientException("Insert request failed after attempts: " + (maxRetries + 1) + " - Duration: " + durationSince(startTime), lastException);
13051305
};
13061306

13071307
return runAsyncOperation(supplier, requestSettings.getAllSettings());
@@ -1480,7 +1480,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14801480

14811481
// Check response
14821482
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1483-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
1483+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
14841484
selectedEndpoint = getNextAliveNode();
14851485
continue;
14861486
}
@@ -1494,7 +1494,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
14941494
return new InsertResponse(metrics);
14951495
} catch (Exception e) {
14961496
lastException = httpClientHelper.wrapException(String.format("Insert failed (Attempt: %s/%s - Duration: %s)",
1497-
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
1497+
(i + 1), (retries + 1), durationSince(startTime)), e);
14981498
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
14991499
LOG.warn("Retrying.", e);
15001500
selectedEndpoint = getNextAliveNode();
@@ -1511,7 +1511,7 @@ public CompletableFuture<InsertResponse> insert(String tableName,
15111511
}
15121512
}
15131513
}
1514-
LOG.warn("Insert request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
1514+
LOG.warn("Insert request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
15151515
throw (lastException == null ? new ClientException("Failed to complete insert operation") : lastException);
15161516
};
15171517

@@ -1603,7 +1603,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16031603

16041604
// Check response
16051605
if (httpResponse.getCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
1606-
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", System.nanoTime() - startTime, httpResponse.getCode());
1606+
LOG.warn("Failed to get response. Server returned {}. Retrying. (Duration: {})", httpResponse.getCode(), durationSince(startTime));
16071607
selectedEndpoint = getNextAliveNode();
16081608
HttpAPIClientHelper.closeQuietly(httpResponse);
16091609
continue;
@@ -1628,7 +1628,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16281628
} catch (Exception e) {
16291629
HttpAPIClientHelper.closeQuietly(httpResponse);
16301630
lastException = httpClientHelper.wrapException(String.format("Query request failed (Attempt: %s/%s - Duration: %s)",
1631-
(i + 1), (retries + 1), System.nanoTime() - startTime), e);
1631+
(i + 1), (retries + 1), durationSince(startTime)), e);
16321632
if (httpClientHelper.shouldRetry(e, requestSettings.getAllSettings())) {
16331633
LOG.warn("Retrying.", e);
16341634
selectedEndpoint = getNextAliveNode();
@@ -1637,7 +1637,7 @@ public CompletableFuture<QueryResponse> query(String sqlQuery, Map<String, Objec
16371637
}
16381638
}
16391639
}
1640-
LOG.warn("Query request failed after attempts: " + (retries + 1) + " - Duration: " + (System.nanoTime() - startTime));
1640+
LOG.warn("Query request failed after attempts: {} - Duration: {}", retries + 1, durationSince(startTime));
16411641
throw (lastException == null ? new ClientException("Failed to complete query") : lastException);
16421642
};
16431643

@@ -1728,14 +1728,12 @@ public List<GenericRecord> queryAll(String sqlQuery, Map<String, Object> params,
17281728
CompletableFuture<QueryResponse> f = query(sqlQuery, params, requestSettings);
17291729
try (QueryResponse response = operationTimeout == 0 ? f.get() : f.get(operationTimeout, TimeUnit.MILLISECONDS)) {
17301730
List<GenericRecord> records = new ArrayList<>();
1731-
if (response.getResultRows() > 0) {
1732-
RowBinaryWithNamesAndTypesFormatReader reader =
1733-
(RowBinaryWithNamesAndTypesFormatReader) newBinaryFormatReader(response);
1731+
RowBinaryWithNamesAndTypesFormatReader reader =
1732+
(RowBinaryWithNamesAndTypesFormatReader) newBinaryFormatReader(response);
17341733

1735-
Map<String, Object> record;
1736-
while (reader.readRecord((record = new LinkedHashMap<>()))) {
1737-
records.add(new MapBackedRecord(record, reader.getConvertions(), reader.getSchema()));
1738-
}
1734+
Map<String, Object> record;
1735+
while (reader.readRecord((record = new LinkedHashMap<>()))) {
1736+
records.add(new MapBackedRecord(record, reader.getConvertions(), reader.getSchema()));
17391737
}
17401738
return records;
17411739
}
@@ -2115,4 +2113,7 @@ private Map<String, Object> buildRequestSettings(Map<String, Object> opSettings)
21152113
return requestSettings;
21162114
}
21172115

2116+
private Duration durationSince(long sinceNanos) {
2117+
return Duration.ofNanos(System.nanoTime() - sinceNanos);
2118+
}
21182119
}

0 commit comments

Comments
 (0)