use of com.facebook.presto.client.QueryResults in project presto by prestodb.
the class StatementResource method getQueryResults.
private static Response getQueryResults(Query query, Optional<Long> token, UriInfo uriInfo, Duration wait) throws InterruptedException {
QueryResults queryResults;
if (token.isPresent()) {
queryResults = query.getResults(token.get(), uriInfo, wait);
} else {
queryResults = query.getNextResults(uriInfo, wait);
}
ResponseBuilder response = Response.ok(queryResults);
// add set session properties
query.getSetSessionProperties().entrySet().forEach(entry -> response.header(PRESTO_SET_SESSION, entry.getKey() + '=' + entry.getValue()));
// add clear session properties
query.getResetSessionProperties().forEach(name -> response.header(PRESTO_CLEAR_SESSION, name));
// add added prepare statements
for (Entry<String, String> entry : query.getAddedPreparedStatements().entrySet()) {
String encodedKey = urlEncode(entry.getKey());
String encodedValue = urlEncode(entry.getValue());
response.header(PRESTO_ADDED_PREPARE, encodedKey + '=' + encodedValue);
}
// add deallocated prepare statements
for (String name : query.getDeallocatedPreparedStatements()) {
response.header(PRESTO_DEALLOCATED_PREPARE, urlEncode(name));
}
// add new transaction ID
query.getStartedTransactionId().ifPresent(transactionId -> response.header(PRESTO_STARTED_TRANSACTION_ID, transactionId));
// add clear transaction ID directive
if (query.isClearTransactionId()) {
response.header(PRESTO_CLEAR_TRANSACTION_ID, true);
}
return response.build();
}
use of com.facebook.presto.client.QueryResults in project presto by prestodb.
the class QueryExecutionClientUtil method runToCompletion.
public static void runToCompletion(HttpClient client, TestingPrestoServer server, String sql, String user) {
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
QueryResults queryResults = postQuery(client, sql, uri, user);
while (queryResults.getNextUri() != null) {
queryResults = getQueryResults(client, queryResults, user);
}
}
use of com.facebook.presto.client.QueryResults in project presto by prestodb.
the class QueryExecutionClientUtil method runToFirstResult.
public static void runToFirstResult(HttpClient client, TestingPrestoServer server, String sql, String user) {
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
QueryResults queryResults = postQuery(client, sql, uri, user);
while (queryResults.getData() == null) {
queryResults = getQueryResults(client, queryResults, user);
}
}
use of com.facebook.presto.client.QueryResults in project presto by prestodb.
the class TestQueryResource method runToFirstResult.
private void runToFirstResult(String sql) {
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
QueryResults queryResults = postQuery(sql, uri);
while (queryResults.getData() == null) {
queryResults = getQueryResults(queryResults);
}
}
use of com.facebook.presto.client.QueryResults in project presto by prestodb.
the class TestQueryResource method runToQueued.
private void runToQueued(String sql) {
URI uri = uriBuilderFrom(server.getBaseUrl().resolve("/v1/statement")).build();
QueryResults queryResults = postQuery(sql, uri);
while (!"QUEUED".equals(queryResults.getStats().getState())) {
queryResults = getQueryResults(queryResults);
}
getQueryResults(queryResults);
}
Aggregations