Search in sources :

Example 16 with StatementClient

use of io.prestosql.client.StatementClient in project hetu-core by openlookeng.

the class TestFinalQueryInfo method startQuery.

private static QueryId startQuery(String sql, DistributedQueryRunner queryRunner) {
    OkHttpClient httpClient = new OkHttpClient();
    try {
        ClientSession clientSession = new ClientSession(queryRunner.getCoordinator().getBaseUrl(), "user", "source", Optional.empty(), ImmutableSet.of(), null, null, null, null, ZoneId.of("America/Los_Angeles"), Locale.ENGLISH, ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), null, new Duration(2, MINUTES));
        // start query
        StatementClient client = newStatementClient(httpClient, clientSession, sql);
        // wait for query to be fully scheduled
        while (client.isRunning() && !client.currentStatusInfo().getStats().isScheduled()) {
            client.advance();
        }
        return new QueryId(client.currentStatusInfo().getId());
    } finally {
        // close the client since, query is not managed by the client protocol
        httpClient.dispatcher().executorService().shutdown();
        httpClient.connectionPool().evictAll();
    }
}
Also used : OkHttpClient(okhttp3.OkHttpClient) ClientSession(io.prestosql.client.ClientSession) QueryId(io.prestosql.spi.QueryId) StatementClient(io.prestosql.client.StatementClient) StatementClientFactory.newStatementClient(io.prestosql.client.StatementClientFactory.newStatementClient) Duration(io.airlift.units.Duration)

Aggregations

StatementClient (io.prestosql.client.StatementClient)16 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)5 DataCenterStatementClient (io.prestosql.client.DataCenterStatementClient)4 QueryData (io.prestosql.client.QueryData)4 QueryStatusInfo (io.prestosql.client.QueryStatusInfo)4 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)4 SQLException (java.sql.SQLException)4 Duration (io.airlift.units.Duration)3 ClientSession (io.prestosql.client.ClientSession)3 QueryError (io.prestosql.client.QueryError)3 QueryClient (io.prestosql.queryeditorui.execution.QueryClient)3 Nullable (javax.annotation.Nullable)3 DataCenterClientSession (io.prestosql.client.DataCenterClientSession)2 QueryRunner (io.prestosql.queryeditorui.execution.QueryRunner)2 QueryId (io.prestosql.spi.QueryId)2 LinkedList (java.util.LinkedList)2 OkHttpClient (okhttp3.OkHttpClient)2 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableMap (com.google.common.collect.ImmutableMap)1