Search in sources :

Example 11 with QueryStatusInfo

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

the class AbstractTestingPrestoClient method execute.

public ResultWithQueryId<T> execute(Session session, @Language("SQL") String sql) {
    ResultsSession<T> resultsSession = getResultSession(session);
    ClientSession clientSession = toClientSession(session, prestoServer.getBaseUrl(), new Duration(2, TimeUnit.MINUTES));
    try (StatementClient client = newStatementClient(httpClient, clientSession, sql)) {
        while (client.isRunning()) {
            resultsSession.addResults(client.currentStatusInfo(), client.currentData());
            client.advance();
        }
        checkState(client.isFinished());
        QueryError error = client.finalStatusInfo().getError();
        if (error == null) {
            QueryStatusInfo results = client.finalStatusInfo();
            if (results.getUpdateType() != null) {
                resultsSession.setUpdateType(results.getUpdateType());
            }
            if (results.getUpdateCount() != null) {
                resultsSession.setUpdateCount(results.getUpdateCount());
            }
            resultsSession.setWarnings(results.getWarnings());
            T result = resultsSession.build(client.getSetSessionProperties(), client.getResetSessionProperties());
            return new ResultWithQueryId<>(new QueryId(results.getId()), result);
        }
        if (error.getFailureInfo() != null) {
            RuntimeException remoteException = error.getFailureInfo().toException();
            throw new RuntimeException(Optional.ofNullable(remoteException.getMessage()).orElseGet(remoteException::toString), remoteException);
        }
        throw new RuntimeException("Query failed: " + error.getMessage());
    // dump query info to console for debugging (NOTE: not pretty printed)
    }
}
Also used : 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) QueryError(io.prestosql.client.QueryError) QueryStatusInfo(io.prestosql.client.QueryStatusInfo)

Aggregations

QueryStatusInfo (io.prestosql.client.QueryStatusInfo)11 QueryError (io.prestosql.client.QueryError)4 StatementClient (io.prestosql.client.StatementClient)4 SQLException (java.sql.SQLException)4 ImmutableList (com.google.common.collect.ImmutableList)2 Duration (io.airlift.units.Duration)2 Column (io.prestosql.client.Column)2 DataCenterStatementClient (io.prestosql.client.DataCenterStatementClient)2 QueryData (io.prestosql.client.QueryData)2 List (java.util.List)2 Duration.succinctDuration (io.airlift.units.Duration.succinctDuration)1 ClientException (io.prestosql.client.ClientException)1 ClientSession (io.prestosql.client.ClientSession)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryResults (io.prestosql.client.QueryResults)1 SnapshotStats (io.prestosql.client.SnapshotStats)1 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)1 StatementStats (io.prestosql.client.StatementStats)1 QueryStats (io.prestosql.execution.QueryStats)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1