use of io.crate.testing.SQLResponse in project crate by crate.
the class SysShardsTest method testSelectStarNotLike.
@Test
public void testSelectStarNotLike() throws Exception {
SQLResponse response = execute("select * from sys.shards where table_name not like 'quotes%'");
assertEquals(18L, response.rowCount());
assertEquals(15, response.cols().length);
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testSetUpdate.
@Test
public void testSetUpdate() throws Exception {
setUpSimple();
execute("insert into t1 (id, byte_field, short_field, integer_field, long_field, " + "float_field, double_field, boolean_field, string_field, timestamp_field," + "object_field) values (?,?,?,?,?,?,?,?,?,?,?)", new Object[] { 0, 0, 0, 0, 0, 0.0f, 1.0, false, "", "1970-01-01", new HashMap<String, Object>() {
{
put("inner", "1970-01-01");
}
} });
execute("update t1 set " + "byte_field=?," + "short_field=?," + "integer_field=?," + "long_field=?," + "float_field=?," + "double_field=?," + "boolean_field=?," + "string_field=?," + "timestamp_field=?," + "object_field=?," + "ip_field=? " + "where id=0", new Object[] { Byte.MAX_VALUE, Short.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, 1.0f, Math.PI, true, "a string", "2013-11-20", new HashMap<String, Object>() {
{
put("inner", "2013-11-20");
}
}, "127.0.0.1" });
refresh();
SQLResponse response = execute("select id, byte_field, short_field, integer_field, long_field," + "float_field, double_field, boolean_field, string_field, timestamp_field," + "object_field, ip_field from t1 where id=0");
assertEquals(1, response.rowCount());
assertEquals(0, response.rows()[0][0]);
assertEquals((byte) 127, response.rows()[0][1]);
assertEquals((short) -32768, response.rows()[0][2]);
assertEquals(0x7fffffff, response.rows()[0][3]);
assertEquals(0x8000000000000000L, response.rows()[0][4]);
assertEquals(1.0f, ((Number) response.rows()[0][5]).floatValue(), 0.01f);
assertEquals(Math.PI, response.rows()[0][6]);
assertEquals(true, response.rows()[0][7]);
assertEquals("a string", response.rows()[0][8]);
assertEquals(1384905600000L, response.rows()[0][9]);
assertEquals(new HashMap<String, Object>() {
{
put("inner", 1384905600000L);
}
}, response.rows()[0][10]);
assertEquals("127.0.0.1", response.rows()[0][11]);
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testInsertNewColumnToIgnoredObject.
@Test
public void testInsertNewColumnToIgnoredObject() throws Exception {
setUpObjectTable();
Map<String, Object> notDynamicContent = new HashMap<String, Object>() {
{
put("new_col", "a string");
put("another_new_col", "1970-01-01T00:00:00");
}
};
execute("insert into test12 (no_dynamic_field) values (?)", new Object[] { notDynamicContent });
refresh();
SQLResponse response = execute("select no_dynamic_field from test12");
assertEquals(1, response.rowCount());
@SuppressWarnings("unchecked") Map<String, Object> selectedNoDynamic = (Map<String, Object>) response.rows()[0][0];
// no mapping applied
assertThat((String) selectedNoDynamic.get("new_col"), is("a string"));
assertThat((String) selectedNoDynamic.get("another_new_col"), is("1970-01-01T00:00:00"));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testInsertTimestampPreferMillis.
@Test
public void testInsertTimestampPreferMillis() throws Exception {
execute("create table ts_table (ts timestamp) clustered into 2 shards with (number_of_replicas=0)");
ensureYellow();
execute("insert into ts_table (ts) values (?)", new Object[] { 1000L });
execute("insert into ts_table (ts) values (?)", new Object[] { "2016" });
refresh();
SQLResponse response = execute("select ts from ts_table order by ts asc");
assertThat((Long) response.rows()[0][0], is(1000L));
assertThat((Long) response.rows()[1][0], is(2016L));
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SQLTypeMappingTest method testInsertAtNodeWithoutShard.
@Test
public void testInsertAtNodeWithoutShard() throws Exception {
setUpSimple(1);
execute("insert into t1 (id, string_field, timestamp_field, byte_field) values (?, ?, ?, ?)", new Object[] { 1, "With", "1970-01-01T00:00:00", 127 }, createSessionOnNode(internalCluster().getNodeNames()[0]));
execute("insert into t1 (id, string_field, timestamp_field, byte_field) values (?, ?, ?, ?)", new Object[] { 2, "Without", "1970-01-01T01:00:00", Byte.MIN_VALUE }, createSessionOnNode(internalCluster().getNodeNames()[1]));
refresh();
SQLResponse response = execute("select id, string_field, timestamp_field, byte_field from t1 order by id");
assertEquals(1, response.rows()[0][0]);
assertEquals("With", response.rows()[0][1]);
assertEquals(0L, response.rows()[0][2]);
assertEquals((byte) 127, response.rows()[0][3]);
assertEquals(2, response.rows()[1][0]);
assertEquals("Without", response.rows()[1][1]);
assertEquals(3600000L, response.rows()[1][2]);
assertEquals((byte) -128, response.rows()[1][3]);
}
Aggregations