Skip to content

Commit

Permalink
New JDBC driver along with improved Java client
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Nov 28, 2021
1 parent 675d382 commit afbb426
Show file tree
Hide file tree
Showing 159 changed files with 17,130 additions and 3,205 deletions.
158 changes: 0 additions & 158 deletions .github/workflows/verify.yml

This file was deleted.

46 changes: 11 additions & 35 deletions clickhouse-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

<properties>
<clickhouse4j-driver.version>1.4.4</clickhouse4j-driver.version>
<mariadb-driver.version>2.7.3</mariadb-driver.version>
<mysql-driver.version>8.0.26</mysql-driver.version>
<native-driver.version>2.5.6</native-driver.version>
<postgresql-driver.version>42.2.23</postgresql-driver.version>
<native-driver.version>2.6.0</native-driver.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jmh.version>1.33</jmh.version>
<shade.name>benchmarks</shade.name>
Expand Down Expand Up @@ -67,10 +64,10 @@

<!-- JDBC drivers -->
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${revision}</version>
<classifier>shaded</classifier>
<classifier>all</classifier>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -79,9 +76,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>cc.blynk.clickhouse</groupId>
<artifactId>clickhouse4j</artifactId>
<version>${clickhouse4j-driver.version}</version>
<groupId>com.github.housepower</groupId>
<artifactId>clickhouse-native-jdbc-shaded</artifactId>
<version>${native-driver.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -90,9 +87,9 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb-driver.version}</version>
<groupId>cc.blynk.clickhouse</groupId>
<artifactId>clickhouse4j</artifactId>
<version>${clickhouse4j-driver.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
Expand All @@ -103,35 +100,14 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-driver.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.housepower</groupId>
<artifactId>clickhouse-native-jdbc-shaded</artifactId>
<version>${native-driver.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql-driver.version}</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.clickhouse.client.ClickHouseResponse;
import com.clickhouse.client.ClickHouseValue;
import com.clickhouse.client.config.ClickHouseClientOption;
import com.clickhouse.client.grpc.config.ClickHouseGrpcClientOption;
import com.clickhouse.client.grpc.config.ClickHouseGrpcOption;

@State(Scope.Thread)
public class ClientState extends BaseState {
Expand Down Expand Up @@ -60,21 +60,22 @@ private ClickHouseClient createClient() {
builder.option(ClickHouseClientOption.MAX_BUFFER_SIZE, Integer.parseInt(bufferSize));
}
if (compression != null && !compression.isEmpty()) {
builder.option(ClickHouseClientOption.COMPRESSION, compression.toUpperCase());
// builder.option(ClickHouseClientOption.COMPRESSION,
// compression.toUpperCase());
if (ClickHouseCompression.NONE.name().equalsIgnoreCase(compression)) {
builder.option(ClickHouseGrpcClientOption.USE_FULL_STREAM_DECOMPRESSION, true);
builder.option(ClickHouseGrpcOption.USE_FULL_STREAM_DECOMPRESSION, true);
}
}
if (threads != null && !threads.isEmpty()) {
builder.option(ClickHouseClientOption.MAX_THREADS_PER_CLIENT, Integer.parseInt(threads));
}

if (window != null && !window.isEmpty()) {
builder.option(ClickHouseGrpcClientOption.FLOW_CONTROL_WINDOW, Integer.parseInt(window));
builder.option(ClickHouseGrpcOption.FLOW_CONTROL_WINDOW, Integer.parseInt(window));
}

return builder.option(ClickHouseClientOption.ASYNC, "async".equals(mode))
.option(ClickHouseGrpcClientOption.USE_OKHTTP, "okhttp".equals(transport)).build();
.option(ClickHouseGrpcOption.USE_OKHTTP, "okhttp".equals(transport)).build();
}

@Setup(Level.Trial)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

@State(Scope.Thread)
public class DriverState extends BaseState {
@Param(value = { "clickhouse4j", "clickhouse-jdbc", "clickhouse-native-jdbc-shaded", "mariadb-java-client",
"mysql-connector-java", "postgresql-jdbc" })
@Param(value = { "clickhouse4j", "clickhouse-http-jdbc", "clickhouse-grpc-jdbc", "clickhouse-jdbc",
"clickhouse-native-jdbc-shaded", "mariadb-java-client", "mysql-connector-java", "postgresql-jdbc" })
private String client;

@Param(value = { Constants.REUSE_CONNECTION, Constants.NEW_CONNECTION })
Expand All @@ -38,11 +38,13 @@ public class DriverState extends BaseState {
public void doSetup(ServerState serverState) throws Exception {
JdbcDriver jdbcDriver = JdbcDriver.from(client);

String compression = String.valueOf(Boolean.parseBoolean(System.getProperty("compression", "true")));

try {
driver = (java.sql.Driver) Class.forName(jdbcDriver.getClassName()).getDeclaredConstructor().newInstance();
url = String.format(jdbcDriver.getUrlTemplate(), serverState.getHost(),
serverState.getPort(jdbcDriver.getDefaultPort()), serverState.getDatabase(), serverState.getUser(),
serverState.getPassword());
serverState.getPassword(), compression);
conn = driver.connect(url, new Properties());

try (Statement s = conn.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@
public enum JdbcDriver {
// ClickHouse4j
Clickhouse4j("cc.blynk.clickhouse.ClickHouseDriver",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.HTTP_PORT),
// ClickHouse JDBC Driver
ClickhouseHttpJdbc("com.clickhouse.jdbc.ClickHouseDriver",
"jdbc:ch://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.HTTP_PORT),
ClickhouseGrpcJdbc("com.clickhouse.jdbc.ClickHouseDriver",
"jdbc:ch:grpc://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.GRPC_PORT),
ClickhouseJdbc("ru.yandex.clickhouse.ClickHouseDriver",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.HTTP_PORT),
// ClickHouse Native JDBC Driver
ClickhouseNativeJdbcShaded("com.github.housepower.jdbc.ClickHouseDriver",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC",
"jdbc:clickhouse://%s:%s/%s?ssl=false&user=%s&password=%s&use_server_time_zone=false&use_time_zone=UTC&compress=%s",
Constants.NATIVE_PORT),

// MariaDB Java Client
MariadbJavaClient("org.mariadb.jdbc.Driver",
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&useSSL=false&useCompression=true&useServerPrepStmts=false"
"jdbc:mariadb://%s:%s/%s?user=%s&password=%s&useSSL=false&useServerPrepStmts=false&useCompression=%s"
+ "&rewriteBatchedStatements=true&cachePrepStmts=true&serverTimezone=UTC",
Constants.MYSQL_PORT),

// MySQL Connector/J
MysqlConnectorJava("com.mysql.cj.jdbc.Driver",
"jdbc:mysql://%s:%s/%s?user=%s&password=%s&useSSL=false&useCompression=true&useServerPrepStmts=false"
+ "&rewriteBatchedStatements=true&cachePrepStmts=true&connectionTimeZone=UTC",
"jdbc:mysql://%s:%s/%s?user=%s&password=%s&useSSL=false&useServerPrepStmts=false"
+ "&rewriteBatchedStatements=true&cachePrepStmts=true&connectionTimeZone=UTC&useCompression=%s",
Constants.MYSQL_PORT),

// PostgreSQL JDBC Driver
PostgresqlJdbc("org.postgresql.Driver",
"jdbc:postgresql://%s:%s/%s?user=%s&password=%s&ssl=false&sslmode=disable&preferQueryMode=simple",
"jdbc:postgresql://%s:%s/%s?user=%s&password=%s&ssl=false&sslmode=disable&preferQueryMode=simple&compress=%s",
Constants.POSTGRESQL_PORT);

private final String className;
Expand Down
Loading

0 comments on commit afbb426

Please sign in to comment.