Search in sources :

Example 76 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnAggAscFuncAndSecondColumnAndLimit.

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

Example 77 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method selectWhereEqualCurrentTimestamp.

@Test
public void selectWhereEqualCurrentTimestamp() throws Exception {
    SQLResponse response = execute("select * from sys.cluster where current_timestamp = current_timestamp");
    assertThat(response.rowCount(), is(1L));
    SQLResponse newResponse = execute("select * from sys.cluster where current_timestamp > current_timestamp");
    assertThat(newResponse.rowCount(), is(0L));
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 78 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCopyToDirectoryOnPartitionedTableWithPartitionClause.

@Test
// copy has no rowcount
@UseJdbc(0)
public void testCopyToDirectoryOnPartitionedTableWithPartitionClause() throws Exception {
    String uriTemplate = Paths.get(folder.getRoot().toURI()).toUri().toString();
    SQLResponse response = execute("copy parted partition (date='2014-01-01') to DIRECTORY ?", $(uriTemplate));
    assertThat(response.rowCount(), is(2L));
    List<String> lines = new ArrayList<>(2);
    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(2));
    for (String line : lines) {
        assertTrue(line.contains("2") || line.contains("1"));
        // date column not included in export
        assertFalse(line.contains("1388534400000"));
        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 79 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method selectCurrentTimestamp.

@Test
public void selectCurrentTimestamp() throws Exception {
    long before = DateTimeUtils.currentTimeMillis();
    SQLResponse response = execute("select current_timestamp from sys.cluster");
    long after = DateTimeUtils.currentTimeMillis();
    assertThat(response.cols(), arrayContaining("current_timestamp"));
    assertThat((long) response.rows()[0][0], allOf(greaterThanOrEqualTo(before), lessThanOrEqualTo(after)));
}
Also used : SQLResponse(io.crate.testing.SQLResponse)

Example 80 with SQLResponse

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

the class TransportSQLActionClassLifecycleTest method testCountWithGroupByOrderOnAggAscFuncAndSecondColumnAndLimitAndOffset.

@Test
public void testCountWithGroupByOrderOnAggAscFuncAndSecondColumnAndLimitAndOffset() throws Exception {
    SQLResponse response = execute("select count(*), gender, race from characters " + "group by race, gender order by count(*) desc, race asc limit 2 offset 2");
    assertEquals(2, response.rowCount());
    assertEquals(2L, response.rows()[0][0]);
    assertEquals("male", response.rows()[0][1]);
    assertEquals("Vogon", response.rows()[0][2]);
    assertEquals(1L, response.rows()[1][0]);
    assertEquals("male", response.rows()[1][1]);
    assertEquals("Android", response.rows()[1][2]);
}
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