use of io.crate.execution.dsl.phases.FetchPhase in project crate by crate.
the class JobSetup method registerContextPhases.
private void registerContextPhases(Iterable<? extends NodeOperation> nodeOperations, Context context) {
for (NodeOperation nodeOperation : nodeOperations) {
// context for nodeOperations without dependencies can be built immediately (e.g. FetchPhase)
if (nodeOperation.downstreamExecutionPhaseId() == NodeOperation.NO_DOWNSTREAM) {
LOGGER.trace("Building context for nodeOp without downstream: {}", nodeOperation);
createContexts(nodeOperation.executionPhase(), context);
context.opCtx.builtNodeOperations.set(nodeOperation.executionPhase().phaseId());
}
if (ExecutionPhases.hasDirectResponseDownstream(nodeOperation.downstreamNodes())) {
var executionPhase = nodeOperation.executionPhase();
CircuitBreaker breaker = breaker();
int ramAccountingBlockSizeInBytes = BlockBasedRamAccounting.blockSizeInBytes(breaker.getLimit());
var ramAccounting = new BlockBasedRamAccounting(b -> breaker.addEstimateBytesAndMaybeBreak(b, executionPhase.label()), ramAccountingBlockSizeInBytes);
Streamer<?>[] streamers = StreamerVisitor.streamersFromOutputs(executionPhase);
SingleBucketBuilder bucketBuilder = new SingleBucketBuilder(streamers, ramAccounting);
context.directResponseFutures.add(bucketBuilder.completionFuture().whenComplete((res, err) -> ramAccounting.close()));
context.registerBatchConsumer(nodeOperation.downstreamExecutionPhaseId(), bucketBuilder);
}
}
}
use of io.crate.execution.dsl.phases.FetchPhase in project crate by crate.
the class FetchTaskTest method testGetIndexServiceForInvalidReaderId.
@Test
public void testGetIndexServiceForInvalidReaderId() throws Exception {
final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, new TreeMap<>(), new HashMap<>(), List.of()), "dummy", new SharedShardContexts(mock(IndicesService.class), UnaryOperator.identity()), clusterService.state().getMetadata(), relationName -> null, Collections.emptyList());
expectedException.expect(IllegalArgumentException.class);
context.indexService(10);
}
use of io.crate.execution.dsl.phases.FetchPhase 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);
}
use of io.crate.execution.dsl.phases.FetchPhase in project crate by crate.
the class FetchPhaseTest method testStreaming.
@Test
public void testStreaming() throws Exception {
RelationName t1 = new RelationName(Schemas.DOC_SCHEMA_NAME, "t1");
TreeMap<String, Integer> bases = new TreeMap<>();
bases.put(t1.name(), 0);
bases.put("i2", 1);
HashMap<RelationName, Collection<String>> tableIndices = new HashMap<>();
tableIndices.put(t1, List.of(t1.name()));
tableIndices.put(new RelationName(Schemas.DOC_SCHEMA_NAME, "i2"), List.of("i2_s1", "i2_s2"));
ReferenceIdent nameIdent = new ReferenceIdent(t1, "name");
Reference name = new Reference(nameIdent, RowGranularity.DOC, DataTypes.STRING, 0, null);
FetchPhase orig = new FetchPhase(1, Set.of("node1", "node2"), bases, tableIndices, List.of(name));
BytesStreamOutput out = new BytesStreamOutput();
ExecutionPhases.toStream(out, orig);
StreamInput in = out.bytes().streamInput();
FetchPhase streamed = (FetchPhase) ExecutionPhases.fromStream(in);
assertThat(orig.phaseId(), is(streamed.phaseId()));
assertThat(orig.nodeIds(), is(streamed.nodeIds()));
assertThat(orig.fetchRefs(), is(streamed.fetchRefs()));
assertThat(orig.bases(), is(streamed.bases()));
assertThat(orig.tableIndices(), is(streamed.tableIndices()));
}
use of io.crate.execution.dsl.phases.FetchPhase in project crate by crate.
the class FetchTaskTest method testSearcherIsAcquiredForShard.
@Test
public void testSearcherIsAcquiredForShard() throws Exception {
IntArrayList shards = IntArrayList.from(1, 2);
Routing routing = new Routing(Map.of("dummy", Map.of("i1", shards)));
IndexBaseBuilder ibb = new IndexBaseBuilder();
ibb.allocate("i1", shards);
Map<RelationName, Collection<String>> tableIndices = new HashMap<>();
tableIndices.put(new RelationName(Schemas.DOC_SCHEMA_NAME, "i1"), List.of("i1"));
Metadata metadata = Metadata.builder().put(IndexMetadata.builder("i1").settings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(SETTING_VERSION_CREATED, Version.CURRENT)).build(), true).build();
final FetchTask context = new FetchTask(UUID.randomUUID(), new FetchPhase(1, null, ibb.build(), tableIndices, List.of(createReference("i1", new ColumnIdent("x"), DataTypes.STRING))), "dummy", new SharedShardContexts(mock(IndicesService.class, RETURNS_MOCKS), UnaryOperator.identity()), metadata, relationName -> null, List.of(routing));
context.start();
assertThat(context.searcher(1), Matchers.notNullValue());
assertThat(context.searcher(2), Matchers.notNullValue());
}
Aggregations