clickhouse-client
的性能比clickhouse-jdbc
要好得多,因为我们有preparedStatment for batchInsert。但是我们如何使用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请求是无状态的,并且是单一的,但是是否还有其他类或方法让批处理插入或我们需要动态地构建带有多个值的insert查询作为查询语句的参数?
发布于 2022-03-08 23:35:23
例如,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
。
我有个问题,你的数据来源是什么?是文件吗?还是某种格式的数据流?
https://stackoverflow.com/questions/71391841
复制相似问题