use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testTwoLevelNestedObjectInArray.
@Test
public void testTwoLevelNestedObjectInArray() throws Exception {
execute("create table assets (\n" + " categories array(object (dynamic) as (\n" + " subcategories object (dynamic) as (\n" + " id int))))");
execute("insert into assets(categories) values ([{subcategories={id=10}}, {subcategories={id=20}}])");
ensureYellow();
execute("refresh table assets");
refresh();
waitNoPendingTasksOnAll();
SQLResponse response = execute("select categories[1]['subcategories']['id'] from assets");
assertEquals(response.rowCount(), 1L);
assertThat((Integer) response.rows()[0][0], is(10));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testInsertNewColumnToObject.
@Test
public void testInsertNewColumnToObject() throws Exception {
setUpObjectTable();
Map<String, Object> objectContent = new HashMap<String, Object>() {
{
put("new_col", "a string");
put("another_new_col", "1970-01-01T00:00:00");
}
};
execute("insert into test12 (object_field) values (?)", new Object[] { objectContent });
refresh();
SQLResponse response = execute("select object_field from test12");
assertEquals(1, response.rowCount());
@SuppressWarnings("unchecked") Map<String, Object> selectedObject = (Map<String, Object>) response.rows()[0][0];
assertThat((String) selectedObject.get("new_col"), is("a string"));
assertEquals("1970-01-01T00:00:00", selectedObject.get("another_new_col"));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testInsertNewObjectColumn.
@Test
public void testInsertNewObjectColumn() throws Exception {
setUpSimple();
execute("insert into t1 (id, new_col) values (?,?)", new Object[] { 0, new HashMap<String, Object>() {
{
put("a_date", "1970-01-01");
put("an_int", 127);
put("a_long", Long.MAX_VALUE);
put("a_boolean", true);
}
} });
refresh();
waitForMappingUpdateOnAll("t1", "new_col");
SQLResponse response = execute("select id, new_col from t1 where id=0");
@SuppressWarnings("unchecked") Map<String, Object> mapped = (Map<String, Object>) response.rows()[0][1];
assertEquals("1970-01-01", mapped.get("a_date"));
assertEquals(127, mapped.get("an_int"));
assertEquals(0x7fffffffffffffffL, mapped.get("a_long"));
assertEquals(true, mapped.get("a_boolean"));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testGetRequestMapping.
@Test
public void testGetRequestMapping() throws Exception {
setUpSimple();
execute("insert into t1 (id, string_field, boolean_field, byte_field, short_field, integer_field," + "long_field, float_field, double_field, object_field," + "timestamp_field, ip_field) values " + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] { 0, "Blabla", true, 120, 1000, 1200000, 120000000000L, 1.4, 3.456789, new HashMap<String, Object>() {
{
put("inner", "1970-01-01");
}
}, "1970-01-01", "127.0.0.1" });
refresh();
SQLResponse getResponse = execute("select * from t1 where id=0");
SQLResponse searchResponse = execute("select * from t1 limit 1");
for (int i = 0; i < getResponse.rows()[0].length; i++) {
assertThat(getResponse.rows()[0][i], is(searchResponse.rows()[0][i]));
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class Setup method setUpArrayTables.
public void setUpArrayTables() {
transportExecutor.exec("create table any_table (" + " id int primary key," + " temps array(double)," + " names array(string)," + " tags array(string)" + ") with (number_of_replicas=0)");
transportExecutor.ensureGreen();
SQLResponse response = transportExecutor.exec("insert into any_table (id, temps, names, tags) values (?,?,?,?), (?,?,?,?), (?,?,?,?), (?,?,?,?)", 1, Arrays.asList(0L, 0L, 0L), Arrays.asList("Dornbirn", "Berlin", "St. Margrethen"), Arrays.asList("cool"), 2, Arrays.asList(0, 1, -1), Arrays.asList("Dornbirn", "Dornbirn", "Dornbirn"), Arrays.asList("cool", null), 3, Arrays.asList(42, -42), Arrays.asList("Hangelsberg", "Berlin"), Arrays.asList("kuhl", "cool"), 4, null, null, Arrays.asList("kuhl", null));
assertThat(response.rowCount(), is(4L));
transportExecutor.exec("refresh table any_table");
}
Aggregations