Search in sources :

Example 86 with SQLResponse

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");
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 87 with SQLResponse

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]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 88 with SQLResponse

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");
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) TestingHelpers.resolveCanonicalString(io.crate.testing.TestingHelpers.resolveCanonicalString) Test(org.junit.Test)

Example 89 with SQLResponse

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");
    }
}
Also used : SQLResponse(io.crate.testing.SQLResponse) Test(org.junit.Test)

Example 90 with SQLResponse

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());
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SQLResponse(io.crate.testing.SQLResponse) SearchResponse(org.elasticsearch.action.search.SearchResponse) Test(org.junit.Test)

Aggregations

SQLResponse (io.crate.testing.SQLResponse)109 Test (org.junit.Test)78 Map (java.util.Map)13 UseJdbc (io.crate.testing.UseJdbc)10 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 PartitionName (io.crate.metadata.PartitionName)4 TestingHelpers.resolveCanonicalString (io.crate.testing.TestingHelpers.resolveCanonicalString)4 Path (java.nio.file.Path)4 BytesRef (org.apache.lucene.util.BytesRef)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 TreeMap (java.util.TreeMap)2 List (java.util.List)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ClusterRerouteRequestBuilder (org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequestBuilder)1 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1