Search in sources :

Example 11 with QueryError

use of io.prestosql.client.QueryError 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

QueryError (io.prestosql.client.QueryError)11 QueryStatusInfo (io.prestosql.client.QueryStatusInfo)4 StatementClient (io.prestosql.client.StatementClient)3 ClientSession (io.prestosql.client.ClientSession)2 FailureInfo (io.prestosql.client.FailureInfo)2 StatementClientFactory.newStatementClient (io.prestosql.client.StatementClientFactory.newStatementClient)2 SQLException (java.sql.SQLException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 Request (io.airlift.http.client.Request)1 Duration (io.airlift.units.Duration)1 Column (io.prestosql.client.Column)1 ErrorLocation (io.prestosql.client.ErrorLocation)1 QueryData (io.prestosql.client.QueryData)1 QueryResults (io.prestosql.client.QueryResults)1 ExecutionFailureInfo (io.prestosql.execution.ExecutionFailureInfo)1 QueryState (io.prestosql.execution.QueryState)1 QueryStats (io.prestosql.execution.QueryStats)1 ExecutionFailureException (io.prestosql.queryeditorui.execution.ExecutionClient.ExecutionFailureException)1