Search in sources :

Example 1 with CountPhase

use of io.crate.execution.dsl.phases.CountPhase in project crate by crate.

the class Count method build.

@Override
public ExecutionPlan build(PlannerContext plannerContext, Set<PlanHint> planHints, ProjectionBuilder projectionBuilder, int limit, int offset, @Nullable OrderBy order, @Nullable Integer pageSizeHint, Row params, SubQueryResults subQueryResults) {
    var normalizer = new EvaluatingNormalizer(plannerContext.nodeContext(), RowGranularity.CLUSTER, null, tableRelation);
    var binder = new SubQueryAndParamBinder(params, subQueryResults).andThen(x -> normalizer.normalize(x, plannerContext.transactionContext()));
    // bind all parameters and possible subQuery values and re-analyze the query
    // (could result in a NO_MATCH, routing could've changed, etc).
    WhereClause boundWhere = WhereClauseAnalyzer.resolvePartitions(where.map(binder), tableRelation, plannerContext.transactionContext(), plannerContext.nodeContext());
    Routing routing = plannerContext.allocateRouting(tableRelation.tableInfo(), boundWhere, RoutingProvider.ShardSelection.ANY, plannerContext.transactionContext().sessionContext());
    CountPhase countPhase = new CountPhase(plannerContext.nextExecutionPhaseId(), routing, Optimizer.optimizeCasts(boundWhere.queryOrFallback(), plannerContext), DistributionInfo.DEFAULT_BROADCAST);
    MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), COUNT_PHASE_NAME, countPhase.nodeIds().size(), 1, Collections.singletonList(plannerContext.handlerNode()), Collections.singletonList(DataTypes.LONG), Collections.singletonList(MergeCountProjection.INSTANCE), DistributionInfo.DEFAULT_BROADCAST, null);
    return new CountPlan(countPhase, mergePhase);
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) CountPhase(io.crate.execution.dsl.phases.CountPhase) CountPlan(io.crate.planner.node.dql.CountPlan)

Example 2 with CountPhase

use of io.crate.execution.dsl.phases.CountPhase in project crate by crate.

the class CountPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Routing routing = new Routing(MapBuilder.<String, Map<String, IntIndexedContainer>>treeMapBuilder().put("n1", MapBuilder.<String, IntIndexedContainer>treeMapBuilder().put("i1", IntArrayList.from(1, 2)).put("i2", IntArrayList.from(1, 2)).map()).put("n2", MapBuilder.<String, IntIndexedContainer>treeMapBuilder().put("i1", IntArrayList.from(3)).map()).map());
    CountPhase countPhase = new CountPhase(1, routing, Literal.BOOLEAN_TRUE, DistributionInfo.DEFAULT_BROADCAST);
    BytesStreamOutput out = new BytesStreamOutput(10);
    countPhase.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    CountPhase streamedNode = new CountPhase(in);
    assertThat(streamedNode.phaseId(), is(1));
    assertThat(streamedNode.nodeIds(), containsInAnyOrder("n1", "n2"));
    assertThat(streamedNode.routing(), equalTo(routing));
    assertThat(streamedNode.distributionInfo(), equalTo(DistributionInfo.DEFAULT_BROADCAST));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) CountPhase(io.crate.execution.dsl.phases.CountPhase) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Aggregations

CountPhase (io.crate.execution.dsl.phases.CountPhase)2 Routing (io.crate.metadata.Routing)2 WhereClause (io.crate.analyze.WhereClause)1 MergePhase (io.crate.execution.dsl.phases.MergePhase)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 CountPlan (io.crate.planner.node.dql.CountPlan)1 Map (java.util.Map)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 Test (org.junit.Test)1