获取批量插入Cassandra中的插入行总数

时间:2017-12-15 09:39:33

标签: cassandra datastax

PreparedStatement preparedStatement = session.prepare("INSERT INTO table_name( column1) VALUES(?)");
BatchStatement batch = new BatchStatement();
batch.add(preparedStatement.bind(value1));
batch.add(preparedStatement.bind(value2));
session.execute(batch);

现在我想知道数据库中插入了多少行。

batch.size();

将仅返回批量大小,而不是插入的记录计数。

1 个答案:

答案 0 :(得分:0)

默认情况下,Cassandra会记录批次,如果成功则保证原子速度。因此,客户端获得的大小与Cassandra中插入的大小相同如果请求成功(否则为0)。

此处有更多信息:https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlBatch.html#cqlBatch__cql-log-unlog

相关问题