Skip to content

Commit

Permalink
bulk operation: add test for bulk args + multi value combination
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasender authored and mfussenegger committed Aug 21, 2014
1 parent 1097267 commit 9ab5826
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,23 @@ public void testInsertWithBulkArgs() throws Exception {
assertThat((Integer) args2.get("id"), is(2));
}

@Test
public void testInsertWithBulkArgsMultiValue() throws Exception {
// should be equal to testInsertWithBulkArgs()
InsertFromValuesAnalysis analysis;
analysis = (InsertFromValuesAnalysis) analyze(
"insert into users (id, name) values (?, ?), (?, ?)",
new Object[][]{
{1, "foo", 2, "bar"} // one bulk row
});
assertThat(analysis.sourceMaps().size(), is(2));
Map<String, Object> args1 = XContentHelper.convertToMap(analysis.sourceMaps().get(0), false).v2();
assertThat((Integer) args1.get("id"), is(1));

Map<String, Object> args2 = XContentHelper.convertToMap(analysis.sourceMaps().get(1), false).v2();
assertThat((Integer) args2.get("id"), is(2));
}

@Test
public void testInsertWithBulkArgsTypeMissMatch() throws Exception {
expectedException.expect(IllegalArgumentException.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public SQLResponse execute(String stmt, Object[] args) {
return response;
}

/**
* Execute an SQL Statement on a random node of the cluster
*
* @param stmt the SQL Statement
* @param bulkArgs the bulk arguments of the statement
* @return the SQLResponse
*/
public SQLResponse execute(String stmt, Object[][] bulkArgs) {
response = sqlExecutor.exec(stmt, bulkArgs);
return response;
}

/**
* Execute an SQL Statement on a random node of the cluster
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3012,6 +3012,20 @@ public void testBulkInsertPartitionedTable() throws Exception {
);
}

@Test
public void testBulkInsert() throws Exception {
execute("create table test (id integer, name string)");
ensureGreen();
execute("insert into test (id, name) values (?, ?), (?, ?)",
new Object[][] {
{1, "Earth", 2, "Saturn"}, // bulk row 1
{3, "Moon", 4, "Mars"} // bulk row 2
});
refresh();
execute("select name from test order by id asc");
assertEquals("Earth\nSaturn\nMoon\nMars\n", TestingHelpers.printedTable(response.rows()));
}

@Test
public void testInsertPartitionedTableOnlyPartitionedColumns() throws Exception {
execute("create table parted (name string, date timestamp)" +
Expand Down
8 changes: 8 additions & 0 deletions sql/src/test/java/io/crate/testing/SQLTransportExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ public SQLResponse exec(String statement, Object... params) {
return execute(statement, params).actionGet();
}

public SQLResponse exec(String statemet, Object[][] bulkArgs) {
return execute(statemet, bulkArgs).actionGet();
}

public ActionFuture<SQLResponse> execute(String statement, Object[] params) {
return clientProvider.client().execute(SQLAction.INSTANCE, new SQLRequest(statement, params));
}

public ActionFuture<SQLResponse> execute(String statement, Object[][] bulkArgs) {
return clientProvider.client().execute(SQLAction.INSTANCE, new SQLRequest(statement, bulkArgs));
}

public ClusterHealthStatus ensureGreen() {
ClusterHealthResponse actionGet = client().admin().cluster().health(
Requests.clusterHealthRequest()
Expand Down

0 comments on commit 9ab5826

Please sign in to comment.