Search in sources :

Example 1 with CountPlan

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

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)));
}
Also used : CountPlan(io.crate.planner.node.dql.CountPlan) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Aggregations

CountPlan (io.crate.planner.node.dql.CountPlan)2 WhereClause (io.crate.analyze.WhereClause)1 CountPhase (io.crate.execution.dsl.phases.CountPhase)1 MergePhase (io.crate.execution.dsl.phases.MergePhase)1 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)1 Routing (io.crate.metadata.Routing)1 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)1 Test (org.junit.Test)1