我们如何使用java clickhouse-client批量插入?

发布于 2025-01-12 08:48:22 字数 521 浏览 0 评论 0原文

clickhouse-client 的性能远远优于 clickhouse-jdbc,我们确实为批量插入准备了PreparedStatment。但是我们如何使用clickhouse-client进行批量插入。

try (ClickHouseClient client = ClickHouseClient.newInstance(preferredProtocol);
    ClickHouseResponse response = client.connect(server)
        .format(preferredFormat)
        .query("insert query")
        .params("param for insert query").execute().get()) {

    }
}

由于http请求是无状态且单一的,但是是否有任何其他类或方法可以批量插入,或者我们需要动态构建插入查询,并使用多个值作为查询语句的参数?

Performance of clickhouse-client is far better than clickhouse-jdbc where we do have preparedStatment for batchInsert. But how can we do Batch insert using clickhouse-client.

try (ClickHouseClient client = ClickHouseClient.newInstance(preferredProtocol);
    ClickHouseResponse response = client.connect(server)
        .format(preferredFormat)
        .query("insert query")
        .params("param for insert query").execute().get()) {

    }
}

As http request is stateless and single but is there any other class or way to have batch insert OR we need to dynamically build insert query with multiple VALUES as parameters for query statement?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗藏城府 2025-01-19 08:48:22

例如 https://github.com/ClickHouse/clickhouse-jdbc

try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol())) {
    ClickHouseRequest<?> request = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes);
    // load data into a table and wait until it's completed
    request.write().query("insert into my_table select c2, c3 from input('c1 UInt8, c2 String, c3 Int32')")
        .data(myInputStream).execute().thenAccept(response -> {
            response.close();
        });

你只需要实现myInputStream

我有一个问题,你的数据来源是什么?它是一个文件吗?或者某种格式的数据流?

For example https://github.com/ClickHouse/clickhouse-jdbc

try (ClickHouseClient client = ClickHouseClient.newInstance(server.getProtocol())) {
    ClickHouseRequest<?> request = client.connect(server).format(ClickHouseFormat.RowBinaryWithNamesAndTypes);
    // load data into a table and wait until it's completed
    request.write().query("insert into my_table select c2, c3 from input('c1 UInt8, c2 String, c3 Int32')")
        .data(myInputStream).execute().thenAccept(response -> {
            response.close();
        });

You just need to implement myInputStream.

I have a question, what is the source of your data? Is it a file? Or stream of data in some format?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文