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