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]);
}
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));
}
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("}"));
}
}
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)));
}
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]);
}
Aggregations