Skip to content

Commit 0673c7f

Browse files
authored
Merge pull request #837 from zhicwu/exception-handling
Prepare patch5
2 parents 95b4807 + 2782a3b commit 0673c7f

File tree

9 files changed

+81
-28
lines changed

9 files changed

+81
-28
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Java 8 or higher is required in order to use Java client([clickhouse-client](htt
9999
<groupId>com.clickhouse</groupId>
100100
<!-- or clickhouse-grpc-client if you prefer gRPC -->
101101
<artifactId>clickhouse-http-client</artifactId>
102-
<version>0.3.2-patch4</version>
102+
<version>0.3.2-patch5</version>
103103
</dependency>
104104
```
105105

@@ -135,7 +135,7 @@ try (ClickHouseClient client = ClickHouseClient.newInstance(preferredProtocol);
135135
<!-- will stop using ru.yandex.clickhouse starting from 0.4.0 -->
136136
<groupId>com.clickhouse</groupId>
137137
<artifactId>clickhouse-jdbc</artifactId>
138-
<version>0.3.2-patch4</version>
138+
<version>0.3.2-patch5</version>
139139
<!-- below is only needed when all you want is a shaded jar -->
140140
<classifier>http</classifier>
141141
<exclusions>
@@ -189,7 +189,7 @@ Use `mvn clean verify` to compile, test and generate shaded packages if you're u
189189

190190
## Benchmark
191191

192-
To benchmark the driver:
192+
To benchmark JDBC drivers for comparison:
193193

194194
```bash
195195
cd clickhouse-benchmark
@@ -198,7 +198,10 @@ mvn -Drelease clean package
198198
java -DdbHost=localhost -jar target/benchmarks.jar -t 1 -p client=clickhouse-http-jdbc1 -p connection=reuse -p statement=prepared Query.selectInt8
199199
```
200200

201-
Note: it's time consuming to run all benchmarks against all drivers using different parameters for comparison. If you just need some numbers to understand performance, please refer to early test results against [0.3.2-test3](https://github.com/ClickHouse/clickhouse-jdbc/issues/768)(still have plenty of room to improve according to ranking at [here](https://github.com/go-faster/ch-bench)).
201+
It's time consuming to run all benchmarks against all drivers using different parameters. If you just need some numbers to understand performance, please refer to table below and some more details like CPU and memory usage mentioned at [here](https://github.com/ClickHouse/clickhouse-jdbc/issues/768)(still have plenty of room to improve according to ranking at [here](https://github.com/go-faster/ch-bench)).
202+
203+
![image](https://user-images.githubusercontent.com/4270380/154429324-631f718d-9277-4522-b60d-13f87b2e6c31.png)
204+
202205

203206
## Testing
204207

clickhouse-benchmark/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<url>https://github.com/ClickHouse/clickhouse-jdbc/tree/master/clickhouse-benchmark</url>
1717

1818
<properties>
19+
<legacy-driver.version>0.3.1-patch</legacy-driver.version>
1920
<clickhouse4j-driver.version>1.4.4</clickhouse4j-driver.version>
2021
<native-driver.version>2.6.4</native-driver.version>
2122
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -36,6 +37,18 @@
3637
<scope>provided</scope>
3738
</dependency>
3839

40+
<dependency>
41+
<groupId>ru.yandex.clickhouse</groupId>
42+
<artifactId>clickhouse-jdbc</artifactId>
43+
<version>${legacy-driver.version}</version>
44+
<classifier>shaded</classifier>
45+
<exclusions>
46+
<exclusion>
47+
<groupId>*</groupId>
48+
<artifactId>*</artifactId>
49+
</exclusion>
50+
</exclusions>
51+
</dependency>
3952
<dependency>
4053
<groupId>${project.parent.groupId}</groupId>
4154
<artifactId>clickhouse-client</artifactId>
@@ -135,6 +148,17 @@
135148
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
136149
</transformers>
137150
<filters>
151+
<filter>
152+
<artifact>com.clickhouse:clickhouse-jdbc</artifact>
153+
<excludes>
154+
<exclude>**/module-info.class</exclude>
155+
<exclude>ru/**</exclude>
156+
<exclude>META-INF/MANIFEST.MF</exclude>
157+
<exclude>META-INF/*.SF</exclude>
158+
<exclude>META-INF/*.DSA</exclude>
159+
<exclude>META-INF/*.RSA</exclude>
160+
</excludes>
161+
</filter>
138162
<filter>
139163
<artifact>*:*</artifact>
140164
<excludes>

clickhouse-client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Async Java client for ClickHouse. `clickhouse-client` is an abstract module, so
99
<dependency>
1010
<groupId>com.clickhouse</groupId>
1111
<artifactId>clickhouse-http-client</artifactId>
12-
<version>0.3.2-patch4</version>
12+
<version>0.3.2-patch5</version>
1313
</dependency>
1414
```
1515

clickhouse-jdbc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Keep in mind that `clickhouse-jdbc` is synchronous, and in general it has more o
1111
<!-- will stop using ru.yandex.clickhouse starting from 0.4.0 -->
1212
<groupId>com.clickhouse</groupId>
1313
<artifactId>clickhouse-jdbc</artifactId>
14-
<version>0.3.2-patch4</version>
14+
<version>0.3.2-patch5</version>
1515
</dependency>
1616
```
1717

clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/internal/ClickHouseStatementImpl.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public int executeUpdate(String sql) throws SQLException {
277277
try (ClickHouseResponse response = getLastResponse(null, null, null)) {
278278
summary = response.getSummary();
279279
} catch (Exception e) {
280-
log.error("can not close stream: %s", e.getMessage());
280+
throw SqlExceptionUtils.handle(e);
281281
}
282282

283283
return summary != null ? (int) summary.getWrittenRows() : 1;
@@ -511,21 +511,28 @@ public void clearBatch() throws SQLException {
511511
public int[] executeBatch() throws SQLException {
512512
ensureOpen();
513513

514+
boolean continueOnError = getConnection().getJdbcConfig().isContinueBatchOnError();
514515
int len = batchStmts.size();
515516
int[] results = new int[len];
516-
for (int i = 0; i < len; i++) {
517-
ClickHouseSqlStatement s = batchStmts.get(i);
518-
try (ClickHouseResponse r = executeStatement(s, null, null, null)) {
519-
updateResult(s, r);
520-
results[i] = currentUpdateCount <= 0 ? 0 : currentUpdateCount;
521-
} catch (Exception e) {
522-
results[i] = EXECUTE_FAILED;
523-
log.error("Faled to execute task %d of %d", i + 1, len, e);
517+
try {
518+
for (int i = 0; i < len; i++) {
519+
ClickHouseSqlStatement s = batchStmts.get(i);
520+
try (ClickHouseResponse r = executeStatement(s, null, null, null)) {
521+
updateResult(s, r);
522+
results[i] = currentUpdateCount <= 0 ? 0 : currentUpdateCount;
523+
} catch (Exception e) {
524+
if (!continueOnError) {
525+
throw SqlExceptionUtils.handle(e);
526+
}
527+
528+
results[i] = EXECUTE_FAILED;
529+
log.error("Faled to execute task %d of %d", i + 1, len, e);
530+
}
524531
}
532+
} finally {
533+
clearBatch();
525534
}
526535

527-
clearBatch();
528-
529536
return results;
530537
}
531538

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHouseStatementTest.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,37 @@ public void testLogComment() throws SQLException {
106106

107107
@Test(groups = "integration")
108108
public void testMutation() throws SQLException {
109-
try (ClickHouseConnection conn = newConnection(new Properties())) {
110-
ClickHouseStatement stmt = conn.createStatement();
111-
stmt.execute("drop table if exists test_mutation;"
112-
+ "create table test_mutation(a String, b UInt32) engine=MergeTree() order by tuple()");
109+
Properties props = new Properties();
110+
try (ClickHouseConnection conn = newConnection(props); ClickHouseStatement stmt = conn.createStatement()) {
111+
Assert.assertFalse(stmt.execute("drop table if exists test_mutation;"
112+
+ "create table test_mutation(a String, b UInt32) engine=MergeTree() order by tuple()"),
113+
"Should not return result set");
113114
// [delete from ]tbl a [delete ]where a.b = 1[ settings mutation_async=0]
114115
// alter table tbl a delete where a.b = 1
115-
stmt.execute("-- test\nselect 1");
116-
stmt.execute("-- test\ndelete from test_mutation where b = 1");
116+
Assert.assertTrue(stmt.execute("-- test\nselect 1"), "Should return a result set");
117+
Assert.assertFalse(stmt.execute("-- test\ndelete from test_mutation where b = 1"),
118+
"Should not return result set");
117119
// [update] tbl a [set] a.b = 1 where a.b != 1[ settings mutation_async=0]
118120
// alter table tbl a update a.b = 1 where a.b != 1
119121
conn.setClientInfo("ApplicationName", "333");
120-
conn.createStatement().execute("update test_mutation set b = 22 where b = 1");
122+
Assert.assertEquals(conn.createStatement().executeUpdate("update test_mutation set b = 22 where b = 1"), 0);
123+
124+
Assert.assertThrows(SQLException.class,
125+
() -> stmt.executeUpdate("update non_exist_table set value=1 where key=1"));
126+
127+
stmt.addBatch("select 1");
128+
stmt.addBatch("select * from non_exist_table");
129+
stmt.addBatch("select 2");
130+
Assert.assertThrows(SQLException.class, () -> stmt.executeBatch());
131+
}
132+
133+
props.setProperty(JdbcConfig.PROP_CONTINUE_BATCH, "true");
134+
try (ClickHouseConnection conn = newConnection(props); ClickHouseStatement stmt = conn.createStatement()) {
135+
stmt.addBatch("select 1");
136+
stmt.addBatch("select * from non_exist_table");
137+
stmt.addBatch("insert into test_mutation values('a',1)");
138+
stmt.addBatch("select 2");
139+
Assert.assertEquals(stmt.executeBatch(), new int[] { 0, ClickHouseStatement.EXECUTE_FAILED, 1, 0 });
121140
}
122141
}
123142

@@ -126,7 +145,7 @@ public void testAsyncInsert() throws SQLException {
126145
if (DEFAULT_PROTOCOL != ClickHouseProtocol.HTTP) {
127146
return;
128147
}
129-
148+
130149
Properties props = new Properties();
131150
try (ClickHouseConnection conn = newConnection(props)) {
132151
if (conn.getServerVersion().check("(,21.12)")) {

examples/grpc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5858

59-
<clickhouse-grpc.version>0.3.2-patch4</clickhouse-grpc.version>
59+
<clickhouse-grpc.version>0.3.2-patch5</clickhouse-grpc.version>
6060

6161
<compiler-plugin.version>3.8.1</compiler-plugin.version>
6262

examples/jdbc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
5858

59-
<clickhouse-jdbc.version>0.3.2-patch4</clickhouse-jdbc.version>
59+
<clickhouse-jdbc.version>0.3.2-patch5</clickhouse-jdbc.version>
6060

6161
<compiler-plugin.version>3.8.1</compiler-plugin.version>
6262

pom.xml

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

9898
<mariadb-driver.version>3.0.3</mariadb-driver.version>
9999
<mysql-driver.version>8.0.28</mysql-driver.version>
100-
<postgresql-driver.version>42.3.2</postgresql-driver.version>
100+
<postgresql-driver.version>42.3.3</postgresql-driver.version>
101101

102102
<repackaged.version>1.1.1</repackaged.version>
103103

0 commit comments

Comments
 (0)