use of io.trino.client.QueryResults in project trino by trinodb.
the class TestServer method testQuery.
@Test
public void testQuery() {
ImmutableList.Builder<List<Object>> data = ImmutableList.builder();
QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator("show catalogs", UTF_8)).setHeader(TRINO_HEADERS.requestCatalog(), "catalog").setHeader(TRINO_HEADERS.requestSchema(), "schema").setHeader(TRINO_HEADERS.requestPath(), "path").setHeader(TRINO_HEADERS.requestClientInfo(), "{\"clientVersion\":\"testVersion\"}").addHeader(TRINO_HEADERS.requestSession(), QUERY_MAX_MEMORY + "=1GB").addHeader(TRINO_HEADERS.requestSession(), JOIN_DISTRIBUTION_TYPE + "=partitioned," + HASH_PARTITION_COUNT + " = 43").addHeader(TRINO_HEADERS.requestPreparedStatement(), "foo=select * from bar")).map(JsonResponse::getValue).peek(result -> assertNull(result.getError())).peek(results -> {
if (results.getData() != null) {
data.addAll(results.getData());
}
}).collect(last());
// get the query info
BasicQueryInfo queryInfo = server.getQueryManager().getQueryInfo(new QueryId(queryResults.getId()));
// verify session properties
assertEquals(queryInfo.getSession().getSystemProperties(), ImmutableMap.builder().put(QUERY_MAX_MEMORY, "1GB").put(JOIN_DISTRIBUTION_TYPE, "partitioned").put(HASH_PARTITION_COUNT, "43").buildOrThrow());
// verify client info in session
assertEquals(queryInfo.getSession().getClientInfo().get(), "{\"clientVersion\":\"testVersion\"}");
// verify prepared statements
assertEquals(queryInfo.getSession().getPreparedStatements(), ImmutableMap.builder().put("foo", "select * from bar").buildOrThrow());
List<List<Object>> rows = data.build();
assertEquals(rows, ImmutableList.of(ImmutableList.of("memory"), ImmutableList.of("system")));
}
use of io.trino.client.QueryResults in project trino by trinodb.
the class TestServer method checkVersionOnError.
private void checkVersionOnError(String query, @Language("RegExp") String proofOfOrigin) {
QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator(query, UTF_8))).map(JsonResponse::getValue).filter(result -> result.getError() != null).findFirst().orElseThrow(() -> new RuntimeException("Error expected"));
assertNull(queryResults.getNextUri());
QueryError queryError = queryResults.getError();
String stackTrace = getStackTraceAsString(queryError.getFailureInfo().toException());
assertThat(stackTrace).containsPattern(proofOfOrigin);
long versionLines = Splitter.on("\n").splitToStream(stackTrace).filter(line -> line.contains("at io.trino.$gen.Trino_testversion____")).count();
if (versionLines != 1) {
fail(format("Expected version embedded in the stacktrace exactly once, but was %s: %s", versionLines, stackTrace));
}
}
Aggregations