Skip to content

Commit 48a6281

Browse files
authored
Merge pull request #777 from zhicwu/enhance-jdbc
The build failure is irrelevant, merge to release `0.3.2-test3`.
2 parents 30bda80 + 7ddc6e0 commit 48a6281

File tree

81 files changed

+2397
-868
lines changed

Some content is hidden

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

81 files changed

+2397
-868
lines changed

.github/workflows/analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6464
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6565
run: |
66-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
66+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
6767
mvn -q --batch-mode --global-toolchains .github/toolchains.xml -Drelease \
6868
-Panalysis verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
6969
continue-on-error: true

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ steps.version.outputs.value }}|g' \
5757
-e 's|^\( <version>\).*\(</version>\)$|\1${{ steps.version.outputs.value }}\2|' \
5858
-e 's|${parent.groupId}|com.clickhouse|g' '{}' \;
59-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
59+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
6060
- name: Build project
6161
run: |
6262
mvn --batch-mode --update-snapshots -q -DskipTests install
@@ -100,7 +100,7 @@ jobs:
100100
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.driver }}|g' \
101101
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.driver }}\2|' \
102102
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
103-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
103+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
104104
continue-on-error: true
105105
- name: Install driver as needed
106106
run: mvn --batch-mode --update-snapshots -q -DskipTests install

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.version }}|g' \
5050
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.version }}\2|' \
5151
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
52-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
52+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
5353
- name: Release Maven package
5454
uses: samuelmeuli/action-maven-publish@v1
5555
with:

.github/workflows/third_party_libs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
find . -type f -name "pom.xml" -exec sed -i -e 's|${revision}|${{ github.event.inputs.version }}|g' \
2626
-e 's|^\( <version>\).*\(</version>\)$|\1${{ github.event.inputs.version }}\2|' \
2727
-e 's|${parent.groupId}|com.clickhouse|g' -e 's|${project.parent.groupId}|com.clickhouse|g' '{}' \;
28-
find . -type f -name "log4j.*" -exec rm -fv '{}' \;
28+
find . -type f -name "simplelogger.*" -exec rm -fv '{}' \;
2929
- name: Release Maven package
3030
uses: samuelmeuli/action-maven-publish@v1
3131
with:

clickhouse-benchmark/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<properties>
1919
<clickhouse4j-driver.version>1.4.4</clickhouse4j-driver.version>
20-
<native-driver.version>2.6.1</native-driver.version>
20+
<native-driver.version>2.6.3</native-driver.version>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<jmh.version>1.33</jmh.version>
2323
<shade.name>benchmarks</shade.name>

clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/jdbc/JdbcDriver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ public enum JdbcDriver {
88
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
99
Constants.HTTP_PORT),
1010
// ClickHouse JDBC Driver
11-
ClickhouseHttpJdbc("com.clickhouse.jdbc.ClickHouseDriver",
12-
"jdbc:ch://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
11+
ClickhouseHttpJdbc1("com.clickhouse.jdbc.ClickHouseDriver",
12+
"jdbc:ch://%s:%s/%s?http_connection_provider=HTTP_URL_CONNECTION&ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
13+
Constants.HTTP_PORT),
14+
ClickhouseHttpJdbc2("com.clickhouse.jdbc.ClickHouseDriver",
15+
"jdbc:ch://%s:%s/%s?http_connection_provider=HTTP_CLIENT&ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
1316
Constants.HTTP_PORT),
1417
ClickhouseGrpcJdbc("com.clickhouse.jdbc.ClickHouseDriver",
1518
"jdbc:ch:grpc://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&max_inbound_message_size=2147483647&compress=%s",

clickhouse-benchmark/src/main/java/com/clickhouse/benchmark/misc/FactoryBenchmark.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openjdk.jmh.annotations.Warmup;
2929
import org.openjdk.jmh.infra.Blackhole;
3030
import com.clickhouse.benchmark.BaseState;
31+
import com.clickhouse.client.ClickHouseEnum;
3132
import com.clickhouse.client.ClickHouseValue;
3233
import com.clickhouse.client.data.ClickHouseBigDecimalValue;
3334
import com.clickhouse.client.data.ClickHouseBigIntegerValue;
@@ -82,7 +83,7 @@ public void setupSamples() {
8283
add(map, list, Double.class, () -> ClickHouseDoubleValue.ofNull());
8384
add(map, list, BigInteger.class, () -> ClickHouseBigIntegerValue.ofNull());
8485
add(map, list, BigDecimal.class, () -> ClickHouseBigDecimalValue.ofNull());
85-
add(map, list, Enum.class, () -> ClickHouseEnumValue.ofNull());
86+
add(map, list, Enum.class, () -> ClickHouseEnumValue.ofNull(ClickHouseEnum.EMPTY));
8687
add(map, list, Inet4Address.class, () -> ClickHouseIpv4Value.ofNull());
8788
add(map, list, Inet6Address.class, () -> ClickHouseIpv6Value.ofNull());
8889

@@ -121,7 +122,7 @@ ClickHouseValue newValue(Class<?> clazz) {
121122
} else if (BigDecimal.class.equals(clazz)) {
122123
return ClickHouseBigDecimalValue.ofNull();
123124
} else if (Enum.class.equals(clazz)) {
124-
return ClickHouseEnumValue.ofNull();
125+
return ClickHouseEnumValue.ofNull(ClickHouseEnum.EMPTY);
125126
} else if (Inet4Address.class.equals(clazz)) {
126127
return ClickHouseIpv4Value.ofNull();
127128
} else if (Inet6Address.class.equals(clazz)) {

clickhouse-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<dependency>
5858
<groupId>org.slf4j</groupId>
59-
<artifactId>slf4j-log4j12</artifactId>
59+
<artifactId>slf4j-simple</artifactId>
6060
<scope>test</scope>
6161
</dependency>
6262
<dependency>

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ public void init(ClickHouseConfig config) {
170170
this.config = config;
171171
if (this.executor == null) { // only initialize once
172172
int threads = config.getMaxThreadsPerClient();
173-
this.executor = threads <= 0 ? ClickHouseClient.getExecutorService()
174-
: ClickHouseUtils.newThreadPool(getClass().getSimpleName(), threads,
175-
config.getMaxQueuedRequests());
173+
this.executor = threads < 1 ? ClickHouseClient.getExecutorService()
174+
: ClickHouseUtils.newThreadPool(this, threads, config.getMaxQueuedRequests());
176175
}
177176

178177
initialized = true;
@@ -196,27 +195,16 @@ public final void close() {
196195
try {
197196
server = null;
198197

199-
if (executor != null) {
200-
executor.shutdown();
201-
}
202-
203198
if (connection != null) {
204199
closeConnection(connection, false);
200+
connection = null;
205201
}
206202

207-
// shutdown* won't shutdown commonPool, so awaitTermination will always time out
208-
// on the other hand, for a client-specific thread pool, we'd better shut it
209-
// down for real
210-
if (executor != null && config.getMaxThreadsPerClient() > 0
211-
&& !executor.awaitTermination(config.getConnectionTimeout(), TimeUnit.MILLISECONDS)) {
212-
executor.shutdownNow();
203+
// avoid shutting down shared thread pool
204+
if (executor != null && config.getMaxThreadsPerClient() > 0 && !executor.isTerminated()) {
205+
executor.shutdown();
213206
}
214-
215207
executor = null;
216-
connection = null;
217-
} catch (InterruptedException e) {
218-
log.warn("Got interrupted when closing client", e);
219-
Thread.currentThread().interrupt();
220208
} catch (Exception e) {
221209
log.warn("Exception occurred when closing client", e);
222210
} finally {
@@ -226,7 +214,7 @@ public final void close() {
226214
closeConnection(connection, true);
227215
}
228216

229-
if (executor != null) {
217+
if (executor != null && config.getMaxThreadsPerClient() > 0) {
230218
executor.shutdownNow();
231219
}
232220
} finally {

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

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import java.util.Objects;
77
import java.util.ServiceLoader;
88
import java.util.concurrent.ExecutorService;
9-
import java.util.concurrent.ForkJoinPool;
109

1110
import com.clickhouse.client.config.ClickHouseOption;
1211
import com.clickhouse.client.config.ClickHouseDefaults;
@@ -23,23 +22,17 @@ public class ClickHouseClientBuilder {
2322
static {
2423
int maxThreads = (int) ClickHouseDefaults.MAX_THREADS.getEffectiveDefaultValue();
2524
int maxRequests = (int) ClickHouseDefaults.MAX_REQUESTS.getEffectiveDefaultValue();
25+
long keepAliveTimeoutMs = (long) ClickHouseDefaults.THREAD_KEEPALIVE_TIMEOUT.getEffectiveDefaultValue();
2626

27-
if (maxThreads <= 0 && maxRequests <= 0) {
28-
// java -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary
29-
// -XX:+PrintNMTStatistics -version
30-
defaultExecutor = ForkJoinPool.commonPool();
31-
} else {
32-
if (maxThreads <= 0) {
33-
maxThreads = Runtime.getRuntime().availableProcessors();
34-
}
35-
36-
if (maxRequests <= 0) {
37-
maxRequests = 0;
38-
}
39-
40-
defaultExecutor = ClickHouseUtils.newThreadPool(ClickHouseClient.class.getSimpleName(), maxThreads,
41-
maxRequests);
27+
if (maxThreads <= 0) {
28+
maxThreads = Runtime.getRuntime().availableProcessors();
29+
}
30+
if (maxRequests <= 0) {
31+
maxRequests = 0;
4232
}
33+
34+
defaultExecutor = ClickHouseUtils.newThreadPool(ClickHouseClient.class.getSimpleName(), maxThreads,
35+
maxThreads * 2, maxRequests, keepAliveTimeoutMs, false);
4336
}
4437

4538
protected ClickHouseConfig config;

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

Lines changed: 69 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -36,69 +36,76 @@ public final class ClickHouseColumn implements Serializable {
3636
private int scale;
3737
private List<ClickHouseColumn> nested;
3838
private List<String> parameters;
39+
private ClickHouseEnum enumConstants;
3940

4041
private int arrayLevel;
4142
private ClickHouseColumn arrayBaseColumn;
4243

4344
private static ClickHouseColumn update(ClickHouseColumn column) {
45+
column.enumConstants = ClickHouseEnum.EMPTY;
4446
int size = column.parameters.size();
4547
switch (column.dataType) {
46-
case Array:
47-
column.arrayLevel = 1;
48-
column.arrayBaseColumn = column.nested.get(0);
49-
while (column.arrayLevel < 255) {
50-
if (column.arrayBaseColumn.dataType == ClickHouseDataType.Array) {
51-
column.arrayLevel++;
52-
column.arrayBaseColumn = column.arrayBaseColumn.nested.get(0);
53-
} else {
54-
break;
48+
case Array:
49+
column.arrayLevel = 1;
50+
column.arrayBaseColumn = column.nested.get(0);
51+
while (column.arrayLevel < 255) {
52+
if (column.arrayBaseColumn.dataType == ClickHouseDataType.Array) {
53+
column.arrayLevel++;
54+
column.arrayBaseColumn = column.arrayBaseColumn.nested.get(0);
55+
} else {
56+
break;
57+
}
5558
}
56-
}
57-
break;
58-
case DateTime:
59-
if (size >= 2) { // same as DateTime64
60-
column.scale = Integer.parseInt(column.parameters.get(0));
61-
column.timeZone = TimeZone.getTimeZone(column.parameters.get(1).replace("'", ""));
62-
} else if (size == 1) { // same as DateTime32
63-
// unfortunately this will fall back to GMT if the time zone
64-
// cannot be resolved
65-
TimeZone tz = TimeZone.getTimeZone(column.parameters.get(0).replace("'", ""));
66-
column.timeZone = tz;
67-
}
68-
break;
69-
case DateTime32:
70-
if (size > 0) {
71-
// unfortunately this will fall back to GMT if the time zone
72-
// cannot be resolved
73-
TimeZone tz = TimeZone.getTimeZone(column.parameters.get(0).replace("'", ""));
74-
column.timeZone = tz;
75-
}
76-
break;
77-
case DateTime64:
78-
if (size > 0) {
59+
break;
60+
case Enum:
61+
case Enum8:
62+
case Enum16:
63+
column.enumConstants = new ClickHouseEnum(column.parameters);
64+
break;
65+
case DateTime:
66+
if (size >= 2) { // same as DateTime64
67+
column.scale = Integer.parseInt(column.parameters.get(0));
68+
column.timeZone = TimeZone.getTimeZone(column.parameters.get(1).replace("'", ""));
69+
} else if (size == 1) { // same as DateTime32
70+
// unfortunately this will fall back to GMT if the time zone
71+
// cannot be resolved
72+
TimeZone tz = TimeZone.getTimeZone(column.parameters.get(0).replace("'", ""));
73+
column.timeZone = tz;
74+
}
75+
break;
76+
case DateTime32:
77+
if (size > 0) {
78+
// unfortunately this will fall back to GMT if the time zone
79+
// cannot be resolved
80+
TimeZone tz = TimeZone.getTimeZone(column.parameters.get(0).replace("'", ""));
81+
column.timeZone = tz;
82+
}
83+
break;
84+
case DateTime64:
85+
if (size > 0) {
86+
column.scale = Integer.parseInt(column.parameters.get(0));
87+
}
88+
if (size > 1) {
89+
column.timeZone = TimeZone.getTimeZone(column.parameters.get(1).replace("'", ""));
90+
}
91+
break;
92+
case Decimal:
93+
if (size >= 2) {
94+
column.precision = Integer.parseInt(column.parameters.get(0));
95+
column.scale = Integer.parseInt(column.parameters.get(1));
96+
}
97+
break;
98+
case Decimal32:
99+
case Decimal64:
100+
case Decimal128:
101+
case Decimal256:
79102
column.scale = Integer.parseInt(column.parameters.get(0));
80-
}
81-
if (size > 1) {
82-
column.timeZone = TimeZone.getTimeZone(column.parameters.get(1).replace("'", ""));
83-
}
84-
break;
85-
case Decimal:
86-
if (size >= 2) {
103+
break;
104+
case FixedString:
87105
column.precision = Integer.parseInt(column.parameters.get(0));
88-
column.scale = Integer.parseInt(column.parameters.get(1));
89-
}
90-
break;
91-
case Decimal32:
92-
case Decimal64:
93-
case Decimal128:
94-
case Decimal256:
95-
column.scale = Integer.parseInt(column.parameters.get(0));
96-
break;
97-
case FixedString:
98-
column.precision = Integer.parseInt(column.parameters.get(0));
99-
break;
100-
default:
101-
break;
106+
break;
107+
default:
108+
break;
102109
}
103110

104111
return column;
@@ -395,6 +402,11 @@ public boolean isArray() {
395402
return dataType == ClickHouseDataType.Array;
396403
}
397404

405+
public boolean isEnum() {
406+
return dataType == ClickHouseDataType.Enum || dataType == ClickHouseDataType.Enum8
407+
|| dataType == ClickHouseDataType.Enum16;
408+
}
409+
398410
public boolean isMap() {
399411
return dataType == ClickHouseDataType.Map;
400412
}
@@ -419,6 +431,10 @@ public ClickHouseDataType getDataType() {
419431
return dataType;
420432
}
421433

434+
public ClickHouseEnum getEnumConstants() {
435+
return enumConstants;
436+
}
437+
422438
public String getOriginalTypeName() {
423439
return originalTypeName;
424440
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ public enum ClickHouseDataType {
4545
UInt64(Long.class, false, true, false, 8, 20, 0, 0, 0, "BIGINT UNSIGNED"),
4646
UInt128(BigInteger.class, false, true, false, 16, 39, 0, 0, 0),
4747
UInt256(BigInteger.class, false, true, false, 32, 78, 0, 0, 0), Int8(Byte.class, false, true, true, 1, 3, 0, 0, 0,
48-
"BOOL", "BOOLEAN", "BYTE", "INT1", "INT1 SIGNED", "TINYINT", "TINYINT SIGNED"),
48+
"BYTE", "INT1", "INT1 SIGNED", "TINYINT", "TINYINT SIGNED"),
4949
Int16(Short.class, false, true, true, 2, 5, 0, 0, 0, "SMALLINT", "SMALLINT SIGNED"),
5050
Int32(Integer.class, false, true, true, 4, 10, 0, 0, 0, "INT", "INTEGER", "MEDIUMINT", "INT SIGNED",
5151
"INTEGER SIGNED", "MEDIUMINT SIGNED"),
5252
Int64(Long.class, false, true, true, 8, 19, 0, 0, 0, "BIGINT", "BIGINT SIGNED"),
5353
Int128(BigInteger.class, false, true, true, 16, 39, 0, 0, 0),
5454
Int256(BigInteger.class, false, true, true, 32, 77, 0, 0, 0),
55+
Bool(Boolean.class, false, false, true, 1, 3, 0, 0, 0, "BOOLEAN"),
5556
Date(LocalDate.class, false, false, false, 2, 10, 0, 0, 0),
5657
Date32(LocalDate.class, false, false, false, 4, 10, 0, 0, 0),
5758
DateTime(LocalDateTime.class, true, false, false, 0, 29, 0, 0, 9, "TIMESTAMP"),

0 commit comments

Comments
 (0)