Search in sources :

Example 11 with StatementClient

use of com.facebook.presto.client.StatementClient in project presto by prestodb.

the class PrestoStatement method execute.

@Override
public boolean execute(String sql) throws SQLException {
    clearCurrentResults();
    checkOpen();
    StatementClient client = null;
    ResultSet resultSet = null;
    try {
        client = connection().startQuery(sql);
        if (client.isFailed()) {
            throw resultsException(client.finalResults());
        }
        resultSet = new PrestoResultSet(client, maxRows.get(), progressConsumer);
        checkSetOrResetSession(client);
        // check if this is a query
        if (client.current().getUpdateType() == null) {
            currentResult.set(resultSet);
            return true;
        }
        // this is an update, not a query
        while (resultSet.next()) {
        // ignore rows
        }
        Long updateCount = client.finalResults().getUpdateCount();
        currentUpdateCount.set((updateCount != null) ? updateCount : 0);
        return false;
    } catch (RuntimeException e) {
        throw new SQLException("Error executing query", e);
    } finally {
        if (currentResult.get() == null) {
            if (resultSet != null) {
                resultSet.close();
            }
            if (client != null) {
                client.close();
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) StatementClient(com.facebook.presto.client.StatementClient) ResultSet(java.sql.ResultSet) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

StatementClient (com.facebook.presto.client.StatementClient)11 QueryResults (com.facebook.presto.client.QueryResults)7 ImmutableList (com.google.common.collect.ImmutableList)6 List (java.util.List)6 Nullable (javax.annotation.Nullable)5 QueryClient (com.airbnb.airpal.core.execution.QueryClient)4 QueryRunner (com.airbnb.airpal.presto.QueryRunner)4 QueryError (com.facebook.presto.client.QueryError)4 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)2 Column (com.facebook.presto.client.Column)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 BasicQueryInfo (com.airbnb.airpal.presto.QueryInfoClient.BasicQueryInfo)1 Table (com.airbnb.airpal.presto.Table)1 HivePartition (com.airbnb.airpal.presto.hive.HivePartition)1