Skip to content

Commit

Permalink
Merge pull request #800 from zhicwu/patch-release
Browse files Browse the repository at this point in the history
Prepare 0.3.2-patch1 release
  • Loading branch information
zhicwu authored Jan 8, 2022
2 parents 6e4b5a7 + 6f4b879 commit 75a6aa6
Show file tree
Hide file tree
Showing 12 changed files with 498 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Java 8 or higher is required in order to use Java client([clickhouse-client](htt
<groupId>com.clickhouse</groupId>
<!-- or clickhouse-grpc-client if you prefer gRPC -->
<artifactId>clickhouse-http-client</artifactId>
<version>0.3.2</version>
<version>0.3.2-patch1</version>
</dependency>
```

Expand Down Expand Up @@ -135,7 +135,7 @@ try (ClickHouseClient client = ClickHouseClient.newInstance(preferredProtocol);
<!-- will stop using ru.yandex.clickhouse starting from 0.4.0 -->
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2</version>
<version>0.3.2-patch1</version>
<!-- below is only needed when all you want is a shaded jar -->
<classifier>http</classifier>
<exclusions>
Expand Down
2 changes: 1 addition & 1 deletion clickhouse-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Async Java client for ClickHouse. `clickhouse-client` is an abstract module, so
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-http-client</artifactId>
<version>0.3.2</version>
<version>0.3.2-patch1</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,9 @@ protected CompletableFuture<ClickHouseResponse> executeAsync(ClickHouseRequest<?
// return new ClickHouseGrpcFuture(server, sealedRequest, requestObserver,
// responseObserver);
return CompletableFuture.supplyAsync(() -> {
int timeout = sealedRequest.getConfig().getConnectionTimeout() / 1000
+ sealedRequest.getConfig().getMaxExecutionTime();
ClickHouseConfig config = sealedRequest.getConfig();
int timeout = config.getConnectionTimeout() / 1000
+ Math.max(config.getSocketTimeout() / 1000, config.getMaxExecutionTime());
try {
if (!responseObserver.await(timeout, TimeUnit.SECONDS)) {
if (!Context.current().withCancellation().cancel(new StatusException(Status.CANCELLED))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.grpc.StatusException;
import io.grpc.stub.StreamObserver;
import com.clickhouse.client.ClickHouseChecker;
import com.clickhouse.client.ClickHouseConfig;
import com.clickhouse.client.ClickHouseNode;
import com.clickhouse.client.ClickHouseRequest;
import com.clickhouse.client.ClickHouseResponse;
Expand Down Expand Up @@ -63,7 +64,10 @@ public boolean isDone() {
@Override
public ClickHouseResponse get() throws InterruptedException, ExecutionException {
try {
return get(request.getConfig().getConnectionTimeout() / 1000 + request.getConfig().getMaxExecutionTime(),
ClickHouseConfig config = request.getConfig();
return get(
config.getConnectionTimeout() / 1000
+ Math.max(config.getSocketTimeout() / 1000, config.getMaxExecutionTime()),
TimeUnit.SECONDS);
} catch (TimeoutException e) {
cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void setError(Throwable error) {
protected boolean updateStatus(Result result) {
summary.update();

log.info(() -> {
log.debug(() -> {
for (LogEntry e : result.getLogsList()) {
String logLevel = e.getLevel().name();
int index = logLevel.indexOf('_');
Expand Down
2 changes: 1 addition & 1 deletion clickhouse-jdbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Keep in mind that `clickhouse-jdbc` is synchronous, and in general it has more o
<!-- will stop using ru.yandex.clickhouse starting from 0.4.0 -->
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.3.2</version>
<version>0.3.2-patch1</version>
</dependency>
```

Expand Down
99 changes: 99 additions & 0 deletions examples/grpc/pom.xml
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 examples/grpc/src/main/java/com/clickhouse/examples/jdbc/Main.java
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();
}
}
}
99 changes: 99 additions & 0 deletions examples/jdbc/pom.xml
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>
Loading

0 comments on commit 75a6aa6

Please sign in to comment.