Search in sources :

Example 6 with RowAccountingWithEstimators

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());
}
Also used : RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) Row(io.crate.data.Row) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) Test(org.junit.Test)

Example 7 with RowAccountingWithEstimators

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());
}
Also used : DescribeResult(io.crate.action.sql.DescribeResult) CircuitBreaker(org.elasticsearch.common.breaker.CircuitBreaker) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) BlockBasedRamAccounting(io.crate.breaker.BlockBasedRamAccounting) RamAccounting(io.crate.breaker.RamAccounting) Symbol(io.crate.expression.symbol.Symbol) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)7 Row (io.crate.data.Row)5 Test (org.junit.Test)4 RamAccounting (io.crate.breaker.RamAccounting)3 ArrayList (java.util.ArrayList)3 OrderBy (io.crate.analyze.OrderBy)2 RowAccountingWithEstimatorsTest (io.crate.breaker.RowAccountingWithEstimatorsTest)2 Symbol (io.crate.expression.symbol.Symbol)2 DataType (io.crate.types.DataType)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 DescribeResult (io.crate.action.sql.DescribeResult)1 SymbolEvaluator.evaluateWithoutParams (io.crate.analyze.SymbolEvaluator.evaluateWithoutParams)1 WindowDefinition (io.crate.analyze.WindowDefinition)1 BlockBasedRamAccounting (io.crate.breaker.BlockBasedRamAccounting)1 ConcurrentRamAccounting (io.crate.breaker.ConcurrentRamAccounting)1 Input (io.crate.data.Input)1 Projector (io.crate.data.Projector)1 WindowAggProjection (io.crate.execution.dsl.projection.WindowAggProjection)1 AggregationFunction (io.crate.execution.engine.aggregation.AggregationFunction)1