use of io.crate.execution.dsl.projection.FetchProjection in project crate by crate.
the class FetchProjector method create.
public static Projector create(FetchProjection projection, RamAccounting ramAccounting, LongSupplier getBucketsBytesThreshold, TransactionContext txnCtx, NodeContext nodeCtx, FetchOperation fetchOperation) {
final FetchRows fetchRows = FetchRows.create(txnCtx, nodeCtx, projection.fetchSources(), projection.outputSymbols());
EstimateCellsSize estimateRowSize = new EstimateCellsSize(projection.inputTypes());
return (BatchIterator<Row> source) -> {
final long maxBucketsSizeInBytes = getBucketsBytesThreshold.getAsLong();
BatchIterator<ReaderBuckets> buckets = BatchIterators.partition(source, projection.getFetchSize(), () -> new ReaderBuckets(fetchRows, projection::getFetchSourceByReader, estimateRowSize, ramAccounting), ReaderBuckets::add, readerBuckets -> readerBuckets.ramBytesUsed() > maxBucketsSizeInBytes);
return new AsyncFlatMapBatchIterator<>(buckets, new FetchMapper(fetchOperation, projection.nodeReaders()));
};
}
use of io.crate.execution.dsl.projection.FetchProjection in project crate by crate.
the class Fetch method build.
@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> hints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
plannerContext.newReaderAllocations();
var executionPlan = Merge.ensureOnHandler(source.build(plannerContext, hints, projectionBuilder, limit, offset, order, pageSizeHint, params, subQueryResults), plannerContext);
ReaderAllocations readerAllocations = plannerContext.buildReaderAllocations();
Function<Symbol, Symbol> paramBinder = new SubQueryAndParamBinder(params, subQueryResults);
FetchPhase fetchPhase = new FetchPhase(plannerContext.nextExecutionPhaseId(), readerAllocations.nodeReaders().keySet(), readerAllocations.bases(), readerAllocations.tableIndices(), fetchRefs);
ArrayList<Symbol> boundOutputs = new ArrayList<>(replacedOutputs.size());
for (var entry : replacedOutputs.entrySet()) {
Symbol key = entry.getKey();
Symbol value = entry.getValue();
if (source.outputs().contains(key)) {
boundOutputs.add(paramBinder.apply(key));
} else {
boundOutputs.add(paramBinder.apply(value));
}
}
List<DataType<?>> inputTypes = Symbols.typeView(source.outputs());
List<Symbol> fetchOutputs = InputColumns.create(boundOutputs, new InputColumns.SourceSymbols(source.outputs()));
FetchProjection fetchProjection = new FetchProjection(fetchPhase.phaseId(), plannerContext.fetchSize(), fetchSourceByRelation, fetchOutputs, inputTypes, readerAllocations.nodeReaders(), readerAllocations.indices(), readerAllocations.indicesToIdents());
executionPlan.addProjection(fetchProjection);
return new QueryThenFetch(executionPlan, fetchPhase);
}
Aggregations