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);
}
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));
}
Aggregations