use of io.crate.planner.node.dql.CountPlan 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.planner.node.dql.CountPlan in project crate by crate.
the class PushDownTest method test_count_start_aggregate_filter_on_aliased_table_is_pushed_down.
@Test
public void test_count_start_aggregate_filter_on_aliased_table_is_pushed_down() {
String stmt = "SELECT COUNT(*) FILTER (WHERE x > 1) FROM t1 as t";
var plan = plan(stmt);
var expectedPlan = "Count[doc.t1 | (x > 1)]";
assertThat(plan, isPlan(expectedPlan));
CountPlan count = (CountPlan) sqlExecutor.plan(stmt);
assertThat(count.countPhase().where(), SymbolMatchers.isFunction("op_>", SymbolMatchers.isReference("x"), SymbolMatchers.isLiteral(1)));
}
Aggregations