-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #800 from zhicwu/patch-release
Prepare 0.3.2-patch1 release
- Loading branch information
Showing
12 changed files
with
498 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.clickhouse</groupId> | ||
<artifactId>grpc-examples</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>grpc-examples</name> | ||
<description>gRPC Examples</description> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc</url> | ||
<inceptionYear>2022</inceptionYear> | ||
|
||
<organization> | ||
<name>ClickHouse, Inc.</name> | ||
<url>https://clickhouse.com/</url> | ||
</organization> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>zhicwu</id> | ||
<name>Zhichun Wu</name> | ||
<email>[email protected]</email> | ||
<timezone>+8</timezone> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc</url> | ||
<connection>scm:[email protected]:ClickHouse/clickhouse-jdbc.git</connection> | ||
<developerConnection>scm:[email protected]:ClickHouse/clickhouse-jdbc.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<issueManagement> | ||
<system>Github</system> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc/issues</url> | ||
</issueManagement> | ||
|
||
<ciManagement> | ||
<system>Github</system> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc/actions</url> | ||
</ciManagement> | ||
|
||
<properties> | ||
<project.current.year>2022</project.current.year> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
||
<clickhouse-grpc.version>0.3.2</clickhouse-grpc.version> | ||
|
||
<compiler-plugin.version>3.8.1</compiler-plugin.version> | ||
|
||
<minJdk>1.8</minJdk> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.clickhouse</groupId> | ||
<artifactId>clickhouse-grpc-client</artifactId> | ||
<version>${clickhouse-grpc.version}</version> | ||
<classifier>shaded</classifier> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${compiler-plugin.version}</version> | ||
<configuration> | ||
<source>${minJdk}</source> | ||
<target>${minJdk}</target> | ||
<showWarnings>true</showWarnings> | ||
<compilerArgs> | ||
<arg>-Xlint:all</arg> | ||
<!-- arg>-Werror</arg --> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
108 changes: 108 additions & 0 deletions
108
examples/grpc/src/main/java/com/clickhouse/examples/jdbc/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.clickhouse.examples.jdbc; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import com.clickhouse.client.ClickHouseClient; | ||
import com.clickhouse.client.ClickHouseConfig; | ||
import com.clickhouse.client.ClickHouseCredentials; | ||
import com.clickhouse.client.ClickHouseException; | ||
import com.clickhouse.client.ClickHouseFormat; | ||
import com.clickhouse.client.ClickHouseNode; | ||
import com.clickhouse.client.ClickHouseProtocol; | ||
import com.clickhouse.client.ClickHouseRecord; | ||
import com.clickhouse.client.ClickHouseRequest; | ||
import com.clickhouse.client.ClickHouseResponse; | ||
import com.clickhouse.client.ClickHouseResponseSummary; | ||
import com.clickhouse.client.data.BinaryStreamUtils; | ||
import com.clickhouse.client.data.ClickHousePipedStream; | ||
|
||
public class Main { | ||
static void dropAndCreateTable(ClickHouseNode server, String table) throws ClickHouseException { | ||
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol())) { | ||
ClickHouseRequest<?> request = client.connect(server); | ||
// or use future chaining | ||
request.query("drop table if exists " + table).execute().get(); | ||
request.query("create table " + table + "(a String, b Nullable(String)) engine=MergeTree() order by a") | ||
.execute().get(); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw ClickHouseException.forCancellation(e, server); | ||
} catch (ExecutionException e) { | ||
throw ClickHouseException.of(e, server); | ||
} | ||
} | ||
|
||
static long insert(ClickHouseNode server, String table) throws ClickHouseException { | ||
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol())) { | ||
ClickHouseRequest.Mutation request = client.connect(server).write().table(table) | ||
.format(ClickHouseFormat.RowBinary); | ||
ClickHouseConfig config = request.getConfig(); | ||
CompletableFuture<ClickHouseResponse> future; | ||
// back-pressuring is not supported, you can adjust the first two arguments | ||
try (ClickHousePipedStream stream = new ClickHousePipedStream(config.getMaxBufferSize(), | ||
config.getMaxQueuedBuffers(), config.getSocketTimeout())) { | ||
// in async mode, which is default, execution happens in a worker thread | ||
future = request.data(stream.getInput()).execute(); | ||
|
||
// writing happens in main thread | ||
for (int i = 0; i < 1000000; i++) { | ||
BinaryStreamUtils.writeString(stream, String.valueOf(i % 16)); | ||
BinaryStreamUtils.writeNonNull(stream); | ||
BinaryStreamUtils.writeString(stream, UUID.randomUUID().toString()); | ||
} | ||
} | ||
|
||
// response should be always closed | ||
try (ClickHouseResponse response = future.get()) { | ||
ClickHouseResponseSummary summary = response.getSummary(); | ||
return summary.getWrittenRows(); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw ClickHouseException.forCancellation(e, server); | ||
} catch (ExecutionException | IOException e) { | ||
throw ClickHouseException.of(e, server); | ||
} | ||
} | ||
|
||
static int query(ClickHouseNode server, String table) throws ClickHouseException { | ||
try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol()); | ||
ClickHouseResponse response = client.connect(server).query("select * from " + table).execute().get()) { | ||
int count = 0; | ||
// or use stream API via response.stream() | ||
for (ClickHouseRecord rec : response.records()) { | ||
count++; | ||
} | ||
return count; | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
throw ClickHouseException.forCancellation(e, server); | ||
} catch (ExecutionException e) { | ||
throw ClickHouseException.of(e, server); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
ClickHouseNode server = ClickHouseNode.builder() | ||
.host(System.getProperty("chHost", "192.168.3.16")) | ||
.port(ClickHouseProtocol.GRPC, Integer.parseInt(System.getProperty("chPort", "9100"))) | ||
.database("system").credentials(ClickHouseCredentials.fromUserAndPassword( | ||
System.getProperty("chUser", "default"), System.getProperty("chPassword", ""))) | ||
.build(); | ||
|
||
String table = "grpc_example_table"; | ||
|
||
try { | ||
dropAndCreateTable(server, table); | ||
|
||
insert(server, table); | ||
|
||
query(server, table); | ||
} catch (ClickHouseException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.clickhouse</groupId> | ||
<artifactId>jdbc-examples</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>jdbc-examples</name> | ||
<description>JDBC Examples</description> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc</url> | ||
<inceptionYear>2022</inceptionYear> | ||
|
||
<organization> | ||
<name>ClickHouse, Inc.</name> | ||
<url>https://clickhouse.com/</url> | ||
</organization> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>zhicwu</id> | ||
<name>Zhichun Wu</name> | ||
<email>[email protected]</email> | ||
<timezone>+8</timezone> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc</url> | ||
<connection>scm:[email protected]:ClickHouse/clickhouse-jdbc.git</connection> | ||
<developerConnection>scm:[email protected]:ClickHouse/clickhouse-jdbc.git</developerConnection> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<issueManagement> | ||
<system>Github</system> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc/issues</url> | ||
</issueManagement> | ||
|
||
<ciManagement> | ||
<system>Github</system> | ||
<url>https://github.com/ClickHouse/clickhouse-jdbc/actions</url> | ||
</ciManagement> | ||
|
||
<properties> | ||
<project.current.year>2022</project.current.year> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
|
||
<clickhouse-jdbc.version>0.3.2</clickhouse-jdbc.version> | ||
|
||
<compiler-plugin.version>3.8.1</compiler-plugin.version> | ||
|
||
<minJdk>1.8</minJdk> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.clickhouse</groupId> | ||
<artifactId>clickhouse-jdbc</artifactId> | ||
<version>${clickhouse-jdbc.version}</version> | ||
<classifier>http</classifier> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>*</groupId> | ||
<artifactId>*</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${compiler-plugin.version}</version> | ||
<configuration> | ||
<source>${minJdk}</source> | ||
<target>${minJdk}</target> | ||
<showWarnings>true</showWarnings> | ||
<compilerArgs> | ||
<arg>-Xlint:all</arg> | ||
<!-- arg>-Werror</arg --> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.