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);
}
}
Aggregations