use of io.trino.client.QueryResults in project trino by trinodb.
the class TestServer method testNoTransactionSupport.
@Test
public void testNoTransactionSupport() {
QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator("start transaction", UTF_8))).map(JsonResponse::getValue).filter(result -> result.getError() != null).findFirst().orElseThrow(() -> new RuntimeException("Error expected"));
assertNull(queryResults.getNextUri());
assertEquals(queryResults.getError().getErrorCode(), INCOMPATIBLE_CLIENT.toErrorCode().getCode());
}
use of io.trino.client.QueryResults in project trino by trinodb.
the class TestServer method testInvalidSessionError.
@Test
public void testInvalidSessionError() {
String invalidTimeZone = "this_is_an_invalid_time_zone";
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.requestTimeZone(), invalidTimeZone)).map(JsonResponse::getValue).peek(result -> checkState((result.getError() == null) != (result.getNextUri() == null))).collect(last());
QueryError queryError = queryResults.getError();
assertNotNull(queryError);
TimeZoneNotSupportedException expected = new TimeZoneNotSupportedException(invalidTimeZone);
assertEquals(queryError.getErrorCode(), expected.getErrorCode().getCode());
assertEquals(queryError.getErrorName(), expected.getErrorCode().getName());
assertEquals(queryError.getErrorType(), expected.getErrorCode().getType().name());
assertEquals(queryError.getMessage(), expected.getMessage());
}
use of io.trino.client.QueryResults in project trino by trinodb.
the class TestQueryResource method runToCompletion.
private String runToCompletion(String sql) {
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
Request request = preparePost().setHeader(TRINO_HEADERS.requestUser(), "user").setUri(uri).setBodyGenerator(createStaticBodyGenerator(sql, UTF_8)).build();
QueryResults queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
while (queryResults.getNextUri() != null) {
request = prepareGet().setHeader(TRINO_HEADERS.requestUser(), "user").setUri(queryResults.getNextUri()).build();
queryResults = client.execute(request, createJsonResponseHandler(jsonCodec(QueryResults.class)));
}
return queryResults.getId();
}
use of io.trino.client.QueryResults in project trino by trinodb.
the class ExecutingStatementResource method asyncQueryResults.
private void asyncQueryResults(Query query, long token, Duration maxWait, DataSize targetResultSize, UriInfo uriInfo, AsyncResponse asyncResponse) {
Duration wait = WAIT_ORDERING.min(MAX_WAIT_TIME, maxWait);
if (targetResultSize == null) {
targetResultSize = DEFAULT_TARGET_RESULT_SIZE;
} else {
targetResultSize = Ordering.natural().min(targetResultSize, MAX_TARGET_RESULT_SIZE);
}
ListenableFuture<QueryResults> queryResultsFuture = query.waitForResults(token, uriInfo, wait, targetResultSize);
ListenableFuture<Response> response = Futures.transform(queryResultsFuture, queryResults -> toResponse(query, queryResults), directExecutor());
bindAsyncResponse(asyncResponse, response, responseExecutor);
}
use of io.trino.client.QueryResults in project trino by trinodb.
the class TestServer method testFirstResponseColumns.
@Test
public void testFirstResponseColumns() {
List<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")).map(JsonResponse::getValue).collect(toImmutableList());
QueryResults first = queryResults.get(0);
QueryResults last = queryResults.get(queryResults.size() - 1);
Optional<QueryResults> data = queryResults.stream().filter(results -> results.getData() != null).findFirst();
assertNull(first.getColumns());
assertEquals(first.getStats().getState(), "QUEUED");
assertNull(first.getData());
assertThat(last.getColumns()).hasSize(1);
assertThat(last.getColumns().get(0).getName()).isEqualTo("Catalog");
assertThat(last.getColumns().get(0).getType()).isEqualTo("varchar(6)");
assertEquals(last.getStats().getState(), "FINISHED");
assertThat(data).isPresent();
QueryResults results = data.orElseThrow();
assertThat(results.getData()).containsOnly(ImmutableList.of("memory"), ImmutableList.of("system"));
}
Aggregations