首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用java clickhouse客户机对插入进行批处理?

如何使用java clickhouse客户机对插入进行批处理?
EN

Stack Overflow用户
提问于 2022-03-08 08:14:55
回答 1查看 1.5K关注 0票数 0

clickhouse-client的性能比clickhouse-jdbc要好得多,因为我们有preparedStatment for batchInsert。但是我们如何使用clickhouse-client进行批量插入。

代码语言:javascript
运行
复制
try (ClickHouseClient client = ClickHouseClient.newInstance(preferredProtocol);
    ClickHouseResponse response = client.connect(server)
        .format(preferredFormat)
        .query("insert query")
        .params("param for insert query").execute().get()) {

    }
}

由于http请求是无状态的,并且是单一的,但是是否还有其他类或方法让批处理插入或我们需要动态地构建带有多个值的insert查询作为查询语句的参数?

EN

回答 1

Stack Overflow用户

发布于 2022-03-08 23:35:23

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

代码语言:javascript
运行
复制
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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71391841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档