use of io.crate.planner.ExecutionPlan in project crate by crate.
the class Union 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) {
Integer childPageSizeHint = limit != TopN.NO_LIMIT ? limitAndOffset(limit, offset) : null;
ExecutionPlan left = lhs.build(plannerContext, hints, projectionBuilder, limit + offset, TopN.NO_OFFSET, null, childPageSizeHint, params, subQueryResults);
ExecutionPlan right = rhs.build(plannerContext, hints, projectionBuilder, limit + offset, TopN.NO_OFFSET, null, childPageSizeHint, params, subQueryResults);
addCastsForIncompatibleObjects(right);
if (left.resultDescription().hasRemainingLimitOrOffset()) {
left = Merge.ensureOnHandler(left, plannerContext);
}
if (right.resultDescription().hasRemainingLimitOrOffset()) {
right = Merge.ensureOnHandler(right, plannerContext);
}
ResultDescription leftResultDesc = left.resultDescription();
ResultDescription rightResultDesc = right.resultDescription();
assert DataTypes.isCompatibleType(leftResultDesc.streamOutputs(), rightResultDesc.streamOutputs()) : "Left and right must output the same types, got " + "lhs=" + leftResultDesc.streamOutputs() + ", rhs=" + rightResultDesc.streamOutputs();
MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "union", leftResultDesc.nodeIds().size() + rightResultDesc.nodeIds().size(), 2, Collections.singletonList(plannerContext.handlerNode()), leftResultDesc.streamOutputs(), Collections.emptyList(), DistributionInfo.DEFAULT_BROADCAST, leftResultDesc.orderBy());
return new UnionExecutionPlan(left, right, mergePhase, limit, offset, lhs.outputs().size(), TopN.NO_LIMIT, leftResultDesc.orderBy());
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class Order 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) {
ExecutionPlan plan = source.build(plannerContext, planHints, projectionBuilder, limit, offset, orderBy, pageSizeHint, params, subQueryResults);
if (plan.resultDescription().orderBy() != null) {
// Collect applied ORDER BY eagerly to produce a optimized execution plan;
if (source instanceof Collect) {
return plan;
}
}
if (plan.resultDescription().hasRemainingLimitOrOffset()) {
plan = Merge.ensureOnHandler(plan, plannerContext);
}
InputColumns.SourceSymbols ctx = new InputColumns.SourceSymbols(source.outputs());
List<Symbol> orderByInputColumns = InputColumns.create(this.orderBy.orderBySymbols(), ctx);
ensureOrderByColumnsArePresentInOutputs(orderByInputColumns);
OrderedTopNProjection topNProjection = new OrderedTopNProjection(Limit.limitAndOffset(limit, offset), 0, InputColumns.create(outputs, ctx), orderByInputColumns, this.orderBy.reverseFlags(), this.orderBy.nullsFirst());
PositionalOrderBy positionalOrderBy = PositionalOrderBy.of(this.orderBy, outputs);
plan.addProjection(topNProjection, limit, offset, positionalOrderBy);
return plan;
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class GroupByPlannerTest method testGroupByOnClusteredByColumnPartitionedOnePartition.
@Test
public void testGroupByOnClusteredByColumnPartitionedOnePartition() throws Exception {
var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addPartitionedTable("create table doc.clustered_parted (" + " id integer," + " date timestamp with time zone," + " city string" + ") clustered by (city) partitioned by (date) ", new PartitionName(new RelationName("doc", "clustered_parted"), singletonList("1395874800000")).asIndexName(), new PartitionName(new RelationName("doc", "clustered_parted"), singletonList("1395961200000")).asIndexName()).build();
// only one partition hit
Merge optimizedPlan = e.plan("select count(*), city from clustered_parted where date=1395874800000 group by city");
Collect collect = (Collect) optimizedPlan.subPlan();
assertThat(collect.collectPhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
assertThat(collect.collectPhase().projections().get(0), instanceOf(GroupProjection.class));
assertThat(optimizedPlan.mergePhase().projections().size(), is(0));
// > 1 partition hit
ExecutionPlan executionPlan = e.plan("select count(*), city from clustered_parted where date=1395874800000 or date=1395961200000 group by city");
assertThat(executionPlan, instanceOf(Merge.class));
assertThat(((Merge) executionPlan).subPlan(), instanceOf(Merge.class));
}
use of io.crate.planner.ExecutionPlan in project crate by crate.
the class CollectTest method test.
@Test
public void test() throws Exception {
var e = SQLExecutor.builder(clusterService).addTable("CREATE TABLE t (x int)").build();
TableStats tableStats = new TableStats();
PlannerContext plannerCtx = e.getPlannerContext(clusterService.state());
ProjectionBuilder projectionBuilder = new ProjectionBuilder(e.nodeCtx);
QueriedSelectRelation analyzedRelation = e.analyze("SELECT 123 AS alias, 456 AS alias2 FROM t ORDER BY alias, 2");
LogicalPlanner logicalPlanner = new LogicalPlanner(e.nodeCtx, tableStats, () -> clusterService.state().nodes().getMinNodeVersion());
LogicalPlan operator = logicalPlanner.plan(analyzedRelation, plannerCtx);
ExecutionPlan build = operator.build(plannerCtx, Set.of(), projectionBuilder, -1, 0, null, null, Row.EMPTY, SubQueryResults.EMPTY);
assertThat((((RoutedCollectPhase) ((io.crate.planner.node.dql.Collect) build).collectPhase())).orderBy(), is(nullValue()));
}
Aggregations