@Test
public void testBulkOperations() throws Exception {
execute("create table test (id integer primary key, name string) with (number_of_replicas = 0)");
ensureGreen();
SQLBulkResponse bulkResp = execute("insert into test (id, name) values (?, ?), (?, ?)",
new Object[][] {
{1, "Earth", 2, "Saturn"}, // bulk row 1
{3, "Moon", 4, "Mars"} // bulk row 2
});
assertThat(bulkResp.results().length, is(4));
for (SQLBulkResponse.Result result : bulkResp.results()) {
assertThat(result.rowCount(), is(1L));
}
refresh();
bulkResp = execute("insert into test (id, name) values (?, ?), (?, ?)",
new Object[][] {
{1, "Earth", 2, "Saturn"}, // bulk row 1
{3, "Moon", 4, "Mars"} // bulk row 2
});
assertThat(bulkResp.results().length, is(4));
for (SQLBulkResponse.Result result : bulkResp.results()) {
assertThat(result.rowCount(), is(-2L));
}
execute("select name from test order by id asc");
assertEquals("Earth\nSaturn\nMoon\nMars\n", TestingHelpers.printedTable(response.rows()));
bulkResp = execute("update test set name = 'bulk_update' where id = ?", new Object[][]{
new Object[]{2},
new Object[]{3},
new Object[]{4},
});
assertThat(bulkResp.results().length, is(3));
for (SQLBulkResponse.Result result : bulkResp.results()) {
assertThat(result.rowCount(), is(1L));
}
refresh();
execute("select count(*) from test where name = 'bulk_update'");
assertThat((Long) response.rows()[0][0], is(3L));
bulkResp = execute("delete from test where id = ?", new Object[][] {
new Object[] { 1 },
new Object[] { 3 }
});
assertThat(bulkResp.results().length, is(2));
for (SQLBulkResponse.Result result : bulkResp.results()) {
assertThat(result.rowCount(), is(1L));
}
refresh();
execute("select count(*) from test");