-
Notifications
You must be signed in to change notification settings - Fork 24
批量操作接口
Yunlong Shen edited this page Apr 21, 2023
·
5 revisions
通过批量操作接口,可以一次性执行多个 Mutation:
// 构造单行操作
Insert insert_0 = insert().setRowKey(row(colVal("c1", 0L),
colVal("c2", "row_0")))
.addMutateColVal(colVal("c3", new byte[]{1}))
.addMutateColVal(colVal("c4", 100L));
Insert insert_1 = insert().setRowKey(row(colVal("c1", 4L),
colVal("c2", "row_4")))
.addMutateColVal(colVal("c3", new byte[]{1}))
.addMutateColVal(colVal("c4", 104L));
Update update_0 = update().setRowKey(row(colVal("c1", 4L),
colVal("c2", "row_4")))
.addMutateColVal(colVal("c3", new byte[]{1}))
.addMutateColVal(colVal("c4", 204L));
批量执行所有单行操作
BatchMutationResult batchResult = client.batchMutation("test_mutation")
.addMutation(insert_0)
.addMutation(insert_1, update_0)
.execute();
// 打印结果
for (int idx : batchResult.size()) {
System.out.println(String.format("the %dth mutation affect %d rows", idx,
batchResult.get(idx).getAffectedRows()));
}