Search in sources :

Example 1 with QueryResult

use of com.facebook.presto.benchmark.framework.QueryResult in project presto by prestodb.

the class JdbcPrestoAction method executeOnce.

private <R> QueryResult<R> executeOnce(Statement statement, Optional<ResultSetConverter<R>> converter) {
    String query = formatSql(statement, Optional.empty());
    ProgressMonitor progressMonitor = new ProgressMonitor();
    try (PrestoConnection connection = getConnection()) {
        try (java.sql.Statement jdbcStatement = connection.createStatement()) {
            PrestoStatement prestoStatement = jdbcStatement.unwrap(PrestoStatement.class);
            prestoStatement.setProgressMonitor(progressMonitor);
            ImmutableList.Builder<R> rows = ImmutableList.builder();
            if (converter.isPresent()) {
                try (ResultSet resultSet = jdbcStatement.executeQuery(query)) {
                    while (resultSet.next()) {
                        rows.add(converter.get().apply(resultSet));
                    }
                }
            } else {
                boolean moreResults = jdbcStatement.execute(query);
                if (moreResults) {
                    consumeResultSet(jdbcStatement.getResultSet());
                }
                do {
                    moreResults = jdbcStatement.getMoreResults();
                    if (moreResults) {
                        consumeResultSet(jdbcStatement.getResultSet());
                    }
                } while (moreResults || jdbcStatement.getUpdateCount() != -1);
            }
            checkState(progressMonitor.getLastQueryStats().isPresent(), "lastQueryStats is missing");
            return new QueryResult<>(rows.build(), progressMonitor.getLastQueryStats().get());
        }
    } catch (SQLException e) {
        throw exceptionClassifier.createException(progressMonitor.getLastQueryStats(), e);
    }
}
Also used : SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) PrestoConnection(com.facebook.presto.jdbc.PrestoConnection) PrestoStatement(com.facebook.presto.jdbc.PrestoStatement) QueryResult(com.facebook.presto.benchmark.framework.QueryResult) ResultSet(java.sql.ResultSet)

Aggregations

QueryResult (com.facebook.presto.benchmark.framework.QueryResult)1 PrestoConnection (com.facebook.presto.jdbc.PrestoConnection)1 PrestoStatement (com.facebook.presto.jdbc.PrestoStatement)1 ImmutableList (com.google.common.collect.ImmutableList)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1