@Override
protected MaterializedResult computeActual(@Language("SQL") String sql)
{
ClientSession session = new ClientSession(coordinator.getBaseUrl(), "testuser", "test", "default", "default", true);
try (StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, sql)) {
AtomicBoolean loggedUri = new AtomicBoolean(false);
ImmutableList.Builder<Tuple> rows = ImmutableList.builder();
TupleInfo tupleInfo = null;
while (client.isValid()) {
QueryResults results = client.current();
if (!loggedUri.getAndSet(true)) {
log.info("Query %s: %s?pretty", results.getId(), results.getInfoUri());
}
if ((tupleInfo == null) && (results.getColumns() != null)) {
tupleInfo = getTupleInfo(results.getColumns());
}
if (results.getData() != null) {
rows.addAll(transform(results.getData(), dataToTuple(tupleInfo)));
}
client.advance();
}
if (!client.isFailed()) {
return new MaterializedResult(rows.build(), tupleInfo);
}
QueryError error = client.finalResults().getError();
assert error != null;
if (error.getFailureInfo() != null) {
throw error.getFailureInfo().toException();
}
throw new RuntimeException("Query failed: " + error.getMessage());