clickhouse-java
clickhouse-java copied to clipboard
How do I update the asynchronous write code after I upgrade the dependent version
How do I update the asynchronous write code after I upgrade the dependent version
version: 0.3.1-patch --> 0.6.0-patch3
ClickHouseDataSource clickHouseDataSource = this.clickHouseDataSource;
try (ClickHouseConnection connection = clickHouseDataSource.getConnection();
ClickHouseStatement statement = connection.createStatement()) {
StringBuilder stringBuilder = new StringBuilder();
for (String segment : segments) {
stringBuilder.append(segment).append("\n");
}
String database = clickhouseWriteProperties.getProperty("write.database");
String table = clickhouseWriteProperties.getProperty("write.table");
//version 0.3.1-patch code
//=============================
statement.write()
.sql("insert into " + database + "." + table)
.data(new ByteArrayInputStream(stringBuilder.toString().getBytes(StandardCharsets.UTF_8)),
ClickHouseFormat.CSV)
.send();
//=============================
stringBuilder.setLength(0);
} catch (Exception e) {
e.printStackTrace();
}
Good day, @WellJay !
There are a few changes in Mutation class that is returned by .write():
- no raw sql. There is one methods instead:
table(). Client will generate required SQL itself - format is passed by separate method:
format() - method
send()replaced with twoexecute()(returns Future<ClickHouseResponse>) andexecuteAndWait()(waits for completion and returns response.
Here is an adopted code example:
stmt.write()
.table("table")
.format(ClickHouseFormat.CSV)
.data(new ByteArrayInputStream(stringBuilder.toString().getBytes(StandardCharsets.UTF_8)))
.execute();