Skip to content

create source jar and update examples #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clickhouse-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
<artifactId>jctools-core</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
Expand Down
1 change: 1 addition & 0 deletions clickhouse-cli-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<relocations>
<relocation>
Expand Down
3 changes: 3 additions & 0 deletions clickhouse-grpc-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<relocations>
<relocation>
Expand Down Expand Up @@ -250,6 +251,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>netty</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -341,6 +343,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>okhttp</shadedClassifierName>
<relocations>
Expand Down
1 change: 1 addition & 0 deletions clickhouse-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<relocations>
<relocation>
Expand Down
10 changes: 7 additions & 3 deletions clickhouse-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<url>https://github.com/ClickHouse/clickhouse-java/tree/main/clickhouse-jdbc</url>

<properties>
<httpclient.version>4.5.13</httpclient.version>
<javacc-plugin.version>4.1.4</javacc-plugin.version>
<spec.title>JDBC</spec.title>
<spec.version>4.2</spec.version>
Expand Down Expand Up @@ -89,8 +88,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -170,6 +169,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>shaded</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -248,6 +248,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>all</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -324,6 +325,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>grpc</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -416,6 +418,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>http</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -503,6 +506,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>cli</shadedClassifierName>
<relocations>
Expand Down
2 changes: 2 additions & 0 deletions clickhouse-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>all</shadedClassifierName>
<relocations>
Expand Down Expand Up @@ -313,6 +314,7 @@
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<createDependencyReducedPom>true</createDependencyReducedPom>
<createSourcesJar>true</createSourcesJar>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<shadedClassifierName>http</shadedClassifierName>
<relocations>
Expand Down
4 changes: 3 additions & 1 deletion examples/grpc/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?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">
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ static long insert(ClickHouseNode server, String table) throws ClickHouseExcepti
CompletableFuture<ClickHouseResponse> future;
// back-pressuring is not supported, you can adjust the first two arguments
try (ClickHousePipedOutputStream stream = ClickHouseDataStreamFactory.getInstance()
.createPipedOutputStream(config, null)) {
.createPipedOutputStream(config, (Runnable) null)) {
// in async mode, which is default, execution happens in a worker thread
future = request.data(stream.getInputStream()).execute();

// writing happens in main thread
for (int i = 0; i < 1000000; i++) {
for (int i = 0; i < 10_000; i++) {
BinaryStreamUtils.writeString(stream, String.valueOf(i % 16));
BinaryStreamUtils.writeNonNull(stream);
BinaryStreamUtils.writeString(stream, UUID.randomUUID().toString());
Expand All @@ -74,7 +74,7 @@ static int query(ClickHouseNode server, String table) throws ClickHouseException
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()) {
for (ClickHouseRecord r : response.records()) {
count++;
}
return count;
Expand All @@ -88,7 +88,7 @@ static int query(ClickHouseNode server, String table) throws ClickHouseException

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

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

query(server, table);
System.out.println("Query: " + query(server, table));
} catch (ClickHouseException e) {
e.printStackTrace();
}
Expand Down
10 changes: 9 additions & 1 deletion examples/jdbc/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?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">
<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>
Expand Down Expand Up @@ -65,6 +67,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<clickhouse-jdbc.version>0.4.0</clickhouse-jdbc.version>
<hikaricp.version>4.0.3</hikaricp.version>

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

Expand All @@ -84,6 +87,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>${hikaricp.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import com.clickhouse.data.ClickHouseOutputStream;
import com.clickhouse.data.ClickHouseWriter;
import com.clickhouse.jdbc.ClickHouseDataSource;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class Basic {
static final String TABLE_NAME = "jdbc_example_basic";
Expand Down Expand Up @@ -125,6 +128,7 @@ public void write(ClickHouseOutputStream output) throws IOException {
// this will be executed in a separate thread
for (int i = 0; i < 1_000_000; i++) {
output.writeUnicodeString("a-" + i);
output.writeBoolean(false); // non-null
output.writeUnicodeString("b-" + i);
}
}
Expand All @@ -137,11 +141,11 @@ public void write(ClickHouseOutputStream output) throws IOException {

static int connectWithCustomSettings(String url) throws SQLException {
// comma separated settings
String customSettings = "session_check=0,max_query_size=100";
String customSettings = "session_check=0,max_query_size=1000";
Properties properties = new Properties();
// properties.setProperty(ClickHouseHttpClientOption.CUSTOM_PARAMS.getKey(),
// properties.setProperty(ClickHouseClientOption.CUSTOM_SETTINGS.getKey(),
// customSettings);
properties.setProperty("custom_http_params", customSettings); // limited to http protocol
properties.setProperty("custom_settings", customSettings);
try (Connection conn = getConnection(url, properties);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select 5")) {
Expand Down Expand Up @@ -194,7 +198,7 @@ static void insertByteArray(Connection conn) throws SQLException {
+ "ORDER BY (resource_container, event_type, event_subtype) "
+ "SETTINGS index_granularity = 8192");
try (PreparedStatement stmt = conn.prepareStatement(
"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")) {
"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', ?)")) {
stmt.setObject(1, Collections.singletonMap("key1", "value1"));
stmt.execute();

Expand All @@ -206,18 +210,44 @@ static void insertByteArray(Connection conn) throws SQLException {
}
}

static void usedPooledConnection(String url) throws SQLException {
// connection pooling won't help much in terms of performance,
// because the underlying implementation has its own pool.
// for example: HttpURLConnection has a pool for sockets
HikariConfig poolConfig = new HikariConfig();
poolConfig.setConnectionTimeout(5000L);
poolConfig.setMaximumPoolSize(20);
poolConfig.setMaxLifetime(300_000L);
poolConfig.setDataSource(new ClickHouseDataSource(url));

HikariDataSource ds = new HikariDataSource(poolConfig);

try (Connection conn = ds.getConnection();
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("select 123")) {
System.out.println(rs.next());
System.out.println(rs.getInt(1));
}
}

public static void main(String[] args) {
// jdbc:ch:https://[email protected]:443
// jdbc:ch:https://demo:[email protected]
String url = System.getProperty("chUrl", "jdbc:ch://localhost");

try {
usedPooledConnection(url);
} catch (SQLException e) {
e.printStackTrace();
}

try (Connection conn = getConnection(url)) {
// connectWithCustomSettings(url);
connectWithCustomSettings(url);
insertByteArray(conn);

// System.out.println("Update Count: " + dropAndCreateTable(conn));
// System.out.println("Inserted Rows: " + batchInsert(conn));
// System.out.println("Result Rows: " + query(conn));
System.out.println("Update Count: " + dropAndCreateTable(conn));
System.out.println("Inserted Rows: " + batchInsert(conn));
System.out.println("Result Rows: " + query(conn));
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<testng.version>7.5</testng.version>

<mariadb-driver.version>3.1.1</mariadb-driver.version>
<mysql-driver.version>8.0.31</mysql-driver.version>
<mysql-driver.version>8.0.32</mysql-driver.version>
<postgresql-driver.version>42.5.1</postgresql-driver.version>

<repackaged.version>1.7.0</repackaged.version>
Expand Down Expand Up @@ -348,8 +348,8 @@
</exclusions>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>${mysql-driver.version}</version>
<exclusions>
<exclusion>
Expand Down