Search in sources :

Example 1 with QueryResults

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();
}
Also used : ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) QueryResults(com.facebook.presto.client.QueryResults)

Example 2 with QueryResults

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);
    }
}
Also used : URI(java.net.URI) QueryResults(com.facebook.presto.client.QueryResults)

Example 3 with QueryResults

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);
    }
}
Also used : URI(java.net.URI) QueryResults(com.facebook.presto.client.QueryResults)

Example 4 with QueryResults

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);
    }
}
Also used : URI(java.net.URI) QueryResults(com.facebook.presto.client.QueryResults)

Example 5 with 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);
}
Also used : URI(java.net.URI) QueryResults(com.facebook.presto.client.QueryResults)

Aggregations

QueryResults (com.facebook.presto.client.QueryResults)22 List (java.util.List)9 URI (java.net.URI)8 Request (com.facebook.airlift.http.client.Request)7 ImmutableList (com.google.common.collect.ImmutableList)7 StatementClient (com.facebook.presto.client.StatementClient)5 Nullable (javax.annotation.Nullable)5 Test (org.testng.annotations.Test)5 QueryClient (com.airbnb.airpal.core.execution.QueryClient)4 QueryRunner (com.airbnb.airpal.presto.QueryRunner)4 Column (com.facebook.presto.client.Column)3 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)2 QueryError (com.facebook.presto.client.QueryError)2 JobState (com.airbnb.airpal.api.JobState)1 InvalidQueryException (com.airbnb.airpal.api.output.InvalidQueryException)1 FileTooLargeException (com.airbnb.airpal.api.output.builders.FileTooLargeException)1 JobOutputBuilder (com.airbnb.airpal.api.output.builders.JobOutputBuilder)1 Persistor (com.airbnb.airpal.api.output.persistors.Persistor)1 ExecutionFailureException (com.airbnb.airpal.core.execution.ExecutionClient.ExecutionFailureException)1 QueryTimeOutException (com.airbnb.airpal.core.execution.QueryClient.QueryTimeOutException)1