Skip to content

Commit 03e42c5

Browse files
authored
Merge pull request #1217 from zhicwu/master
create source jar and update examples
2 parents 21ae59a + 33995c2 commit 03e42c5

File tree

11 files changed

+75
-24
lines changed

11 files changed

+75
-24
lines changed

clickhouse-benchmark/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@
122122
<artifactId>jctools-core</artifactId>
123123
</dependency>
124124
<dependency>
125-
<groupId>mysql</groupId>
126-
<artifactId>mysql-connector-java</artifactId>
125+
<groupId>com.mysql</groupId>
126+
<artifactId>mysql-connector-j</artifactId>
127127
</dependency>
128128
<dependency>
129129
<groupId>org.mariadb.jdbc</groupId>

clickhouse-cli-client/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<shadedArtifactAttached>true</shadedArtifactAttached>
8686
<shadedClassifierName>shaded</shadedClassifierName>
8787
<createDependencyReducedPom>true</createDependencyReducedPom>
88+
<createSourcesJar>true</createSourcesJar>
8889
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
8990
<relocations>
9091
<relocation>

clickhouse-grpc-client/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
<shadedArtifactAttached>true</shadedArtifactAttached>
149149
<shadedClassifierName>shaded</shadedClassifierName>
150150
<createDependencyReducedPom>true</createDependencyReducedPom>
151+
<createSourcesJar>true</createSourcesJar>
151152
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
152153
<relocations>
153154
<relocation>
@@ -250,6 +251,7 @@
250251
<configuration>
251252
<shadedArtifactAttached>true</shadedArtifactAttached>
252253
<createDependencyReducedPom>true</createDependencyReducedPom>
254+
<createSourcesJar>true</createSourcesJar>
253255
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
254256
<shadedClassifierName>netty</shadedClassifierName>
255257
<relocations>
@@ -341,6 +343,7 @@
341343
<configuration>
342344
<shadedArtifactAttached>true</shadedArtifactAttached>
343345
<createDependencyReducedPom>true</createDependencyReducedPom>
346+
<createSourcesJar>true</createSourcesJar>
344347
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
345348
<shadedClassifierName>okhttp</shadedClassifierName>
346349
<relocations>

clickhouse-http-client/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
<shadedArtifactAttached>true</shadedArtifactAttached>
116116
<shadedClassifierName>shaded</shadedClassifierName>
117117
<createDependencyReducedPom>true</createDependencyReducedPom>
118+
<createSourcesJar>true</createSourcesJar>
118119
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
119120
<relocations>
120121
<relocation>

clickhouse-jdbc/pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<url>https://github.com/ClickHouse/clickhouse-java/tree/main/clickhouse-jdbc</url>
1818

1919
<properties>
20-
<httpclient.version>4.5.13</httpclient.version>
2120
<javacc-plugin.version>4.1.4</javacc-plugin.version>
2221
<spec.title>JDBC</spec.title>
2322
<spec.version>4.2</spec.version>
@@ -89,8 +88,8 @@
8988
<scope>test</scope>
9089
</dependency>
9190
<dependency>
92-
<groupId>mysql</groupId>
93-
<artifactId>mysql-connector-java</artifactId>
91+
<groupId>com.mysql</groupId>
92+
<artifactId>mysql-connector-j</artifactId>
9493
<scope>test</scope>
9594
</dependency>
9695
</dependencies>
@@ -170,6 +169,7 @@
170169
<configuration>
171170
<shadedArtifactAttached>true</shadedArtifactAttached>
172171
<createDependencyReducedPom>true</createDependencyReducedPom>
172+
<createSourcesJar>true</createSourcesJar>
173173
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
174174
<shadedClassifierName>shaded</shadedClassifierName>
175175
<relocations>
@@ -248,6 +248,7 @@
248248
<configuration>
249249
<shadedArtifactAttached>true</shadedArtifactAttached>
250250
<createDependencyReducedPom>true</createDependencyReducedPom>
251+
<createSourcesJar>true</createSourcesJar>
251252
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
252253
<shadedClassifierName>all</shadedClassifierName>
253254
<relocations>
@@ -324,6 +325,7 @@
324325
<configuration>
325326
<shadedArtifactAttached>true</shadedArtifactAttached>
326327
<createDependencyReducedPom>true</createDependencyReducedPom>
328+
<createSourcesJar>true</createSourcesJar>
327329
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
328330
<shadedClassifierName>grpc</shadedClassifierName>
329331
<relocations>
@@ -416,6 +418,7 @@
416418
<configuration>
417419
<shadedArtifactAttached>true</shadedArtifactAttached>
418420
<createDependencyReducedPom>true</createDependencyReducedPom>
421+
<createSourcesJar>true</createSourcesJar>
419422
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
420423
<shadedClassifierName>http</shadedClassifierName>
421424
<relocations>
@@ -503,6 +506,7 @@
503506
<configuration>
504507
<shadedArtifactAttached>true</shadedArtifactAttached>
505508
<createDependencyReducedPom>true</createDependencyReducedPom>
509+
<createSourcesJar>true</createSourcesJar>
506510
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
507511
<shadedClassifierName>cli</shadedClassifierName>
508512
<relocations>

clickhouse-r2dbc/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
<configuration>
220220
<shadedArtifactAttached>true</shadedArtifactAttached>
221221
<createDependencyReducedPom>true</createDependencyReducedPom>
222+
<createSourcesJar>true</createSourcesJar>
222223
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
223224
<shadedClassifierName>all</shadedClassifierName>
224225
<relocations>
@@ -313,6 +314,7 @@
313314
<configuration>
314315
<shadedArtifactAttached>true</shadedArtifactAttached>
315316
<createDependencyReducedPom>true</createDependencyReducedPom>
317+
<createSourcesJar>true</createSourcesJar>
316318
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
317319
<shadedClassifierName>http</shadedClassifierName>
318320
<relocations>

examples/grpc/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
35
<modelVersion>4.0.0</modelVersion>
46

57
<groupId>com.clickhouse</groupId>

examples/grpc/src/main/java/com/clickhouse/examples/jdbc/Main.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ static long insert(ClickHouseNode server, String table) throws ClickHouseExcepti
4444
CompletableFuture<ClickHouseResponse> future;
4545
// back-pressuring is not supported, you can adjust the first two arguments
4646
try (ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance()
47-
.createPipedOutputStream(config, null)) {
47+
.createPipedOutputStream(config, (Runnable) null)) {
4848
// in async mode, which is default, execution happens in a worker thread
4949
future = request.data(stream.getInputStream()).execute();
5050

5151
// writing happens in main thread
52-
for (int i = 0; i < 1000000; i++) {
52+
for (int i = 0; i < 10_000; i++) {
5353
BinaryStreamUtils.writeString(stream, String.valueOf(i % 16));
5454
BinaryStreamUtils.writeNonNull(stream);
5555
BinaryStreamUtils.writeString(stream, UUID.randomUUID().toString());
@@ -74,7 +74,7 @@ static int query(ClickHouseNode server, String table) throws ClickHouseException
7474
ClickHouseResponse response = client.connect(server).query("select * from " + table).execute().get()) {
7575
int count = 0;
7676
// or use stream API via response.stream()
77-
for (ClickHouseRecord rec : response.records()) {
77+
for (ClickHouseRecord r : response.records()) {
7878
count++;
7979
}
8080
return count;
@@ -88,7 +88,7 @@ static int query(ClickHouseNode server, String table) throws ClickHouseException
8888

8989
public static void main(String[] args) {
9090
ClickHouseNode server = ClickHouseNode.builder()
91-
.host(System.getProperty("chHost", "192.168.3.16"))
91+
.host(System.getProperty("chHost", "127.0.0.1"))
9292
.port(ClickHouseProtocol.GRPC, Integer.parseInt(System.getProperty("chPort", "9100")))
9393
.database("system").credentials(ClickHouseCredentials.fromUserAndPassword(
9494
System.getProperty("chUser", "default"), System.getProperty("chPassword", "")))
@@ -99,9 +99,9 @@ public static void main(String[] args) {
9999
try {
100100
dropAndCreateTable(server, table);
101101

102-
insert(server, table);
102+
System.out.println("Insert: " + insert(server, table));
103103

104-
query(server, table);
104+
System.out.println("Query: " + query(server, table));
105105
} catch (ClickHouseException e) {
106106
e.printStackTrace();
107107
}

examples/jdbc/pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
35
<modelVersion>4.0.0</modelVersion>
46

57
<groupId>com.clickhouse</groupId>
@@ -65,6 +67,7 @@
6567
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
6668

6769
<clickhouse-jdbc.version>0.4.0</clickhouse-jdbc.version>
70+
<hikaricp.version>4.0.3</hikaricp.version>
6871

6972
<compiler-plugin.version>3.8.1</compiler-plugin.version>
7073

@@ -84,6 +87,11 @@
8487
</exclusion>
8588
</exclusions>
8689
</dependency>
90+
<dependency>
91+
<groupId>com.zaxxer</groupId>
92+
<artifactId>HikariCP</artifactId>
93+
<version>${hikaricp.version}</version>
94+
</dependency>
8795
</dependencies>
8896

8997
<build>

examples/jdbc/src/main/java/com/clickhouse/examples/jdbc/Basic.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
import com.clickhouse.data.ClickHouseOutputStream;
1515
import com.clickhouse.data.ClickHouseWriter;
16+
import com.clickhouse.jdbc.ClickHouseDataSource;
17+
import com.zaxxer.hikari.HikariConfig;
18+
import com.zaxxer.hikari.HikariDataSource;
1619

1720
public class Basic {
1821
static final String TABLE_NAME = "jdbc_example_basic";
@@ -125,6 +128,7 @@ public void write(ClickHouseOutputStream output) throws IOException {
125128
// this will be executed in a separate thread
126129
for (int i = 0; i < 1_000_000; i++) {
127130
output.writeUnicodeString("a-" + i);
131+
output.writeBoolean(false); // non-null
128132
output.writeUnicodeString("b-" + i);
129133
}
130134
}
@@ -137,11 +141,11 @@ public void write(ClickHouseOutputStream output) throws IOException {
137141

138142
static int connectWithCustomSettings(String url) throws SQLException {
139143
// comma separated settings
140-
String customSettings = "session_check=0,max_query_size=100";
144+
String customSettings = "session_check=0,max_query_size=1000";
141145
Properties properties = new Properties();
142-
// properties.setProperty(ClickHouseHttpClientOption.CUSTOM_PARAMS.getKey(),
146+
// properties.setProperty(ClickHouseClientOption.CUSTOM_SETTINGS.getKey(),
143147
// customSettings);
144-
properties.setProperty("custom_http_params", customSettings); // limited to http protocol
148+
properties.setProperty("custom_settings", customSettings);
145149
try (Connection conn = getConnection(url, properties);
146150
Statement stmt = conn.createStatement();
147151
ResultSet rs = stmt.executeQuery("select 5")) {
@@ -194,7 +198,7 @@ static void insertByteArray(Connection conn) throws SQLException {
194198
+ "ORDER BY (resource_container, event_type, event_subtype) "
195199
+ "SETTINGS index_granularity = 8192");
196200
try (PreparedStatement stmt = conn.prepareStatement(
197-
"INSERT INTO t_map VALUES (8481365034795008,1673349039830,'operation-9','a','service', 'bc3e47b8-2b34-4c1a-9004-123656fa0000','b', 'c', 'service-56','d', 'object','e', 'my-value-62', 'mypath', 'some.hostname.address.com', 'app-9', 'instance-6','x', ?) SETTINGS async_insert=1,wait_for_async_insert=0")) {
201+
"INSERT INTO t_map SETTINGS async_insert=1,wait_for_async_insert=1 VALUES (8481365034795008,1673349039830,'operation-9','a','service', 'bc3e47b8-2b34-4c1a-9004-123656fa0000','b', 'c', 'service-56','d', 'object','e', 'my-value-62', 'mypath', 'some.hostname.address.com', 'app-9', 'instance-6','x', ?)")) {
198202
stmt.setObject(1, Collections.singletonMap("key1", "value1"));
199203
stmt.execute();
200204

@@ -206,18 +210,44 @@ static void insertByteArray(Connection conn) throws SQLException {
206210
}
207211
}
208212

213+
static void usedPooledConnection(String url) throws SQLException {
214+
// connection pooling won't help much in terms of performance,
215+
// because the underlying implementation has its own pool.
216+
// for example: HttpURLConnection has a pool for sockets
217+
HikariConfig poolConfig = new HikariConfig();
218+
poolConfig.setConnectionTimeout(5000L);
219+
poolConfig.setMaximumPoolSize(20);
220+
poolConfig.setMaxLifetime(300_000L);
221+
poolConfig.setDataSource(new ClickHouseDataSource(url));
222+
223+
HikariDataSource ds = new HikariDataSource(poolConfig);
224+
225+
try (Connection conn = ds.getConnection();
226+
Statement s = conn.createStatement();
227+
ResultSet rs = s.executeQuery("select 123")) {
228+
System.out.println(rs.next());
229+
System.out.println(rs.getInt(1));
230+
}
231+
}
232+
209233
public static void main(String[] args) {
210234
// jdbc:ch:https://explorer@play.clickhouse.com:443
211235
// jdbc:ch:https://demo:demo@github.demo.trial.altinity.cloud
212236
String url = System.getProperty("chUrl", "jdbc:ch://localhost");
213237

238+
try {
239+
usedPooledConnection(url);
240+
} catch (SQLException e) {
241+
e.printStackTrace();
242+
}
243+
214244
try (Connection conn = getConnection(url)) {
215-
// connectWithCustomSettings(url);
245+
connectWithCustomSettings(url);
216246
insertByteArray(conn);
217247

218-
// System.out.println("Update Count: " + dropAndCreateTable(conn));
219-
// System.out.println("Inserted Rows: " + batchInsert(conn));
220-
// System.out.println("Result Rows: " + query(conn));
248+
System.out.println("Update Count: " + dropAndCreateTable(conn));
249+
System.out.println("Inserted Rows: " + batchInsert(conn));
250+
System.out.println("Result Rows: " + query(conn));
221251
} catch (SQLException e) {
222252
e.printStackTrace();
223253
}

0 commit comments

Comments
 (0)