Search in sources :

Example 71 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnAggDescFuncAndLimit.

@Test
public void testCountWithGroupByOrderOnAggDescFuncAndLimit() throws Exception {
    SQLResponse response = execute("select count(*), race from characters group by race order by count(*) desc limit 2");
    assertEquals(2, response.rowCount());
    assertEquals(4L, response.rows()[0][0]);
    assertEquals("Human", response.rows()[0][1]);
    assertEquals(2L, response.rows()[1][0]);
    assertEquals("Vogon", response.rows()[1][1]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 72 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testGroupByNestedObject.

@Test
public void testGroupByNestedObject() throws Exception {
    SQLResponse response = execute("select count(*), details['job'] from characters " + "group by details['job'] order by count(*), details['job']");
    assertEquals(3, response.rowCount());
    assertEquals(1L, response.rows()[0][0]);
    assertEquals("Mathematician", response.rows()[0][1]);
    assertEquals(1L, response.rows()[1][0]);
    assertEquals("Sandwitch Maker", response.rows()[1][1]);
    assertEquals(5L, response.rows()[2][0]);
    assertNull(null, response.rows()[2][1]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 73 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testIsNullOnObjects.

@Test
public void testIsNullOnObjects() throws Exception {
    SQLResponse resp = execute("select name from characters where details is null order by name");
    assertThat(resp.rowCount(), is(5L));
    List<String> names = new ArrayList<>(5);
    for (Object[] objects : resp.rows()) {
        names.add((String) objects[0]);
    }
    assertThat(names, Matchers.contains("Anjie", "Ford Perfect", "Jeltz", "Kwaltz", "Marving"));
    resp = execute("select count(*) from characters where details is not null");
    assertThat((Long) resp.rows()[0][0], is(2L));
}
Also used : ArrayList(java.util.ArrayList) SQLResponse(io.crate.testing.SQLResponse)

Example 74 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testOrderByNullsFirstAndLast.

@Test
public void testOrderByNullsFirstAndLast() throws Exception {
    SQLResponse response = execute("select details['job'] from characters order by details['job'] nulls first limit 1");
    assertNull(response.rows()[0][0]);
    response = execute("select details['job'] from characters order by details['job'] desc nulls first limit 1");
    assertNull(response.rows()[0][0]);
    response = execute("select details['job'] from characters order by details['job'] nulls last");
    assertNull(response.rows()[((Long) response.rowCount()).intValue() - 1][0]);
    response = execute("select details['job'] from characters order by details['job'] desc nulls last");
    assertNull(response.rows()[((Long) response.rowCount()).intValue() - 1][0]);
    response = execute("select distinct details['job'] from characters order by details['job'] desc nulls last");
    assertNull(response.rows()[((Long) response.rowCount()).intValue() - 1][0]);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) SQLResponse(io.crate.testing.SQLResponse)

Example 75 with SQLResponse

use of io.crate.testing.SQLResponse in project crate by crate.

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnAggAscFuncAndLimit.

@Test
public void testCountWithGroupByOrderOnAggAscFuncAndLimit() throws Exception {
    SQLResponse response = execute("select count(*), race from characters " + "group by race order by count(*) asc limit ?", new Object[] { 2 });
    assertEquals(2, response.rowCount());
    assertEquals(1L, response.rows()[0][0]);
    assertEquals("Android", response.rows()[0][1]);
    assertEquals(2L, response.rows()[1][0]);
    assertEquals("Vogon", response.rows()[1][1]);
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

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