use of io.crate.breaker.RowAccountingWithEstimators in project crate by crate.
the class RestActionReceiversTest method testRestResultSetReceiver.
@Test
public void testRestResultSetReceiver() throws Exception {
RestResultSetReceiver receiver = new RestResultSetReceiver(JsonXContent.contentBuilder(), fields, 0L, new RowAccountingWithEstimators(Symbols.typeView(fields), RamAccounting.NO_ACCOUNTING), true);
for (Row row : rows) {
receiver.setNextRow(row);
}
XContentBuilder actualBuilder = receiver.finishBuilder();
ResultToXContentBuilder builder = ResultToXContentBuilder.builder(JsonXContent.contentBuilder());
builder.cols(fields);
builder.colTypes(fields);
builder.startRows();
for (Row row : rows) {
builder.addRow(row, 3);
}
builder.finishRows();
builder.rowCount(rows.size());
assertXContentBuilder(actualBuilder, builder.build());
}
use of io.crate.breaker.RowAccountingWithEstimators in project crate by crate.
the class SqlHttpHandler method executeSimpleRequest.
private CompletableFuture<XContentBuilder> executeSimpleRequest(Session session, String stmt, List<Object> args, boolean includeTypes) throws IOException {
long startTimeInNs = System.nanoTime();
session.parse(UNNAMED, stmt, emptyList());
session.bind(UNNAMED, UNNAMED, args == null ? emptyList() : args, null);
DescribeResult description = session.describe('P', UNNAMED);
List<Symbol> resultFields = description.getFields();
ResultReceiver<XContentBuilder> resultReceiver;
if (resultFields == null) {
resultReceiver = new RestRowCountReceiver(JsonXContent.contentBuilder(), startTimeInNs, includeTypes);
} else {
CircuitBreaker breaker = circuitBreakerProvider.apply(HierarchyCircuitBreakerService.QUERY);
RamAccounting ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, "http-result"), MAX_BLOCK_SIZE_IN_BYTES);
resultReceiver = new RestResultSetReceiver(JsonXContent.contentBuilder(), resultFields, startTimeInNs, new RowAccountingWithEstimators(Symbols.typeView(resultFields), ramAccounting), includeTypes);
resultReceiver.completionFuture().whenComplete((result, error) -> ramAccounting.close());
}
session.execute(UNNAMED, 0, resultReceiver);
return session.sync().thenCompose(ignored -> resultReceiver.completionFuture());
}
Aggregations