Skip to content
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

How do I update the asynchronous write code after I upgrade the dependent version #1617

Open
WellJay opened this issue Apr 23, 2024 · 1 comment
Labels

Comments

@WellJay
Copy link

WellJay commented Apr 23, 2024

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();
}
@chernser
Copy link
Contributor

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 two execute() (returns Future) and executeAndWait() (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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants