Search in sources :

Example 36 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testDistanceQueryOnSysTable.

@Test
public void testDistanceQueryOnSysTable() throws Exception {
    SQLResponse response = execute("select Distance('POINT (10 20)', 'POINT (11 21)') from sys.cluster");
    assertThat((Double) response.rows()[0][0], is(152462.70754934277));
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 37 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCopyToDirectoryOnPartitionedTableWithoutPartitionClause.

@Test
// COPY has no rowcount
@UseJdbc(0)
public void testCopyToDirectoryOnPartitionedTableWithoutPartitionClause() throws Exception {
    String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
    SQLResponse response = execute("copy parted to DIRECTORY ?", $(uriTemplate));
    assertThat(response.rowCount(), is(4L));
    List<String> lines = new ArrayList<>(4);
    DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(folder.getRoot().toURI()), "*.json");
    for (Path entry : stream) {
        lines.addAll(Files.readAllLines(entry, StandardCharsets.UTF_8));
    }
    assertThat(lines.size(), is(4));
    for (String line : lines) {
        // date column included in output
        if (!line.contains("1388534400000")) {
            assertTrue(line.contains("1391212800000"));
        }
        assertThat(line, startsWith("{"));
        assertThat(line, endsWith("}"));
    }
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) SQLResponse(io.crate.testing.SQLResponse) UseJdbc(io.crate.testing.UseJdbc)

Example 38 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnKeyAscAndLimit.

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

Example 39 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testSelectDoc.

@Test
public void testSelectDoc() throws Exception {
    SQLResponse response = execute("select _doc from characters order by name desc limit 1");
    assertArrayEquals(new String[] { "_doc" }, response.cols());
    Map<String, Object> _doc = new TreeMap<>((Map) response.rows()[0][0]);
    assertEquals("{age=32, birthdate=276912000000, details={job=Mathematician}, " + "gender=female, name=Trillian, race=Human}", _doc.toString());
}
Also used : SQLResponse(io.crate.testing.SQLResponse) TreeMap(java.util.TreeMap)

Example 40 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testGlobalAggregateNullRowWithoutMatchingRows.

@Test
public void testGlobalAggregateNullRowWithoutMatchingRows() throws Exception {
    SQLResponse response = execute("select sum(age), avg(age) from characters where characters.age > 112");
    assertEquals(1, response.rowCount());
    assertNull(response.rows()[0][0]);
    assertNull(response.rows()[0][1]);
    response = execute("select sum(age) from characters limit 0");
    assertEquals(0, response.rowCount());
}
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