use of io.crate.testing.SQLResponse in project crate by crate.
the class SysShardsTest method testGroupByWithLimitUnassignedShards.
@Test
public void testGroupByWithLimitUnassignedShards() throws Exception {
try {
execute("create table t (id int, name string) with (number_of_replicas=2)");
ensureYellow();
SQLResponse response = execute("select sum(num_docs), table_name, sum(num_docs) from sys.shards group by table_name order by table_name desc limit 1000");
assertThat(response.rowCount(), is(4L));
assertThat(TestingHelpers.printedTable(response.rows()), is("0.0| t| 0.0\n" + "0.0| quotes| 0.0\n" + "14.0| characters| 14.0\n" + "0.0| blobs| 0.0\n"));
} finally {
execute("drop table t");
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SysShardsTest method testSelectGroupByWhereNotLike.
@Test
public void testSelectGroupByWhereNotLike() throws Exception {
SQLResponse response = execute("select count(*), table_name from sys.shards " + "where table_name not like 'my_table%' group by table_name order by table_name");
assertEquals(3L, response.rowCount());
assertEquals(10L, response.rows()[0][0]);
assertEquals("blobs", response.rows()[0][1]);
assertEquals(8L, response.rows()[1][0]);
assertEquals("characters", response.rows()[1][1]);
assertEquals(8L, response.rows()[2][0]);
assertEquals("quotes", response.rows()[2][1]);
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SysShardsTest method testSelectNodeSysExpressionWithUnassignedShards.
@Test
public void testSelectNodeSysExpressionWithUnassignedShards() throws Exception {
try {
execute("create table users (id integer primary key, name string) " + "clustered into 5 shards with (number_of_replicas=2)");
ensureYellow();
SQLResponse response = execute("select _node['name'], id from sys.shards where table_name = 'users' order by _node['name'] nulls last");
String nodeName = response.rows()[0][0].toString();
assertEquals("node_s0", nodeName);
assertThat(response.rows()[12][0], is(nullValue()));
} finally {
execute("drop table users");
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class SysShardsTest method testOrphanedPartitionExpression.
@Test
public void testOrphanedPartitionExpression() throws Exception {
try {
execute("create table c.orphan_test (id int primary key, p string primary key) " + "partitioned by (p) " + "clustered into 1 shards " + "with (number_of_replicas = 0)");
execute("insert into c.orphan_test (id, p) values (1, 'foo')");
ensureYellow();
SQLResponse response = execute("select orphan_partition from sys.shards where table_name = 'orphan_test'");
assertThat(TestingHelpers.printedTable(response.rows()), is("false\n"));
client().admin().indices().prepareDeleteTemplate(PartitionName.templateName("c", "orphan_test")).execute().get(1, TimeUnit.SECONDS);
response = execute("select orphan_partition from sys.shards where table_name = 'orphan_test'");
assertThat(TestingHelpers.printedTable(response.rows()), is("true\n"));
} finally {
execute("drop table c.orphan_test");
}
}
use of io.crate.testing.SQLResponse in project crate by crate.
the class MappingDefaultsTest method testAllFieldsDisabled.
@Test
public void testAllFieldsDisabled() throws Exception {
execute("create table test (col1 string)");
ensureYellow();
SQLResponse sqlResponse = execute("insert into test (col1) values ('foo')");
assertEquals(1, sqlResponse.rowCount());
refresh();
byte[] searchSource = XContentFactory.jsonBuilder().startObject().startObject("query").startObject("query_string").field("query", "foo").endObject().endObject().endObject().bytes().toBytes();
SearchRequest searchRequest = new SearchRequest("test");
searchRequest.source(searchSource);
SearchResponse response = client().search(searchRequest).actionGet();
assertEquals(0L, response.getHits().totalHits());
}
Aggregations