use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryGlobalAggregate.
@Test
public void testInsertFromSubQueryGlobalAggregate() throws Exception {
Merge globalAggregate = e.plan("insert into users (name, id) (select arbitrary(name), count(*) from users)");
MergePhase mergePhase = globalAggregate.mergePhase();
assertThat(mergePhase.projections().size(), is(3));
assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
assertThat(mergePhase.projections().get(2), instanceOf(ColumnIndexWriterProjection.class));
ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(2);
assertThat(projection.columnReferences().size(), is(2));
assertThat(projection.columnReferences().get(0).ident().columnIdent().fqn(), is("name"));
assertThat(projection.columnReferences().get(1).ident().columnIdent().fqn(), is("id"));
assertThat(projection.columnSymbols().size(), is(2));
assertThat(((InputColumn) projection.columnSymbols().get(0)).index(), is(0));
assertThat(((InputColumn) projection.columnSymbols().get(1)).index(), is(1));
assertNotNull(projection.clusteredByIdent());
assertThat(projection.clusteredByIdent().fqn(), is("id"));
assertThat(projection.tableIdent().fqn(), is("doc.users"));
assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByWithoutLimit.
@Test
public void testInsertFromSubQueryDistributedGroupByWithoutLimit() throws Exception {
Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name)");
DistributedGroupBy groupBy = (DistributedGroupBy) planNode.subPlan();
MergePhase mergePhase = groupBy.reducerMergeNode();
assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(2);
assertThat(projection.primaryKeys().size(), is(1));
assertThat(projection.primaryKeys().get(0).fqn(), is("id"));
assertThat(projection.columnReferences().size(), is(2));
assertThat(projection.columnReferences().get(0).ident().columnIdent().fqn(), is("id"));
assertThat(projection.columnReferences().get(1).ident().columnIdent().fqn(), is("name"));
assertNotNull(projection.clusteredByIdent());
assertThat(projection.clusteredByIdent().fqn(), is("id"));
assertThat(projection.tableIdent().fqn(), is("doc.users"));
assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
MergePhase localMergeNode = planNode.mergePhase();
assertThat(localMergeNode.projections().size(), is(1));
assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
assertThat(localMergeNode.finalProjection().get().outputs().size(), is(1));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryNonDistributedGroupBy.
@Test
public void testInsertFromSubQueryNonDistributedGroupBy() throws Exception {
Merge nonDistributedGroupBy = e.plan("insert into users (id, name) (select count(*), name from sys.nodes group by name)");
MergePhase mergePhase = nonDistributedGroupBy.mergePhase();
assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class Merge method ensureOnHandler.
/**
* Wrap the subPlan into a Merge plan if it isn't executed on the handler.
* @param projections projections to be applied on the subPlan or merge plan.
* These projections must not affect the limit, offset, order by or numOutputs
*
* If the subPlan contains a limit/offset or orderBy in its resultDescription this method will
* add a TopNProjection AFTER the projections.
*/
public static Plan ensureOnHandler(Plan subPlan, Planner.Context plannerContext, List<Projection> projections) {
ResultDescription resultDescription = subPlan.resultDescription();
assert resultDescription != null : "all plans must have a result description. Plan without: " + subPlan;
// If a sub-Plan applies a limit it is usually limit+offset
// So even if the execution is on the handler the limit may be too large and the final limit needs to be applied as well
Projection topN = ProjectionBuilder.topNOrEvalIfNeeded(resultDescription.limit(), resultDescription.offset(), resultDescription.numOutputs(), resultDescription.streamOutputs());
if (ExecutionPhases.executesOnHandler(plannerContext.handlerNode(), resultDescription.nodeIds())) {
return addProjections(subPlan, projections, resultDescription, topN);
}
Collection<String> handlerNodeIds = getHandlerNodeIds(subPlan, plannerContext, resultDescription);
MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "mergeOnHandler", resultDescription.nodeIds().size(), handlerNodeIds, resultDescription.streamOutputs(), addProjection(projections, topN), DistributionInfo.DEFAULT_SAME_NODE, resultDescription.orderBy());
return new Merge(subPlan, mergePhase, TopN.NO_LIMIT, 0, resultDescription.numOutputs(), resultDescription.limit(), null);
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class DistributingDownstreamFactoryTest method createDownstream.
private BatchConsumer createDownstream(Set<String> downstreamExecutionNodes) {
UUID jobId = UUID.randomUUID();
Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).map()).map());
RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, ImmutableList.<Symbol>of(), ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, Collections.emptyList(), ImmutableList.<DataType>of(LongType.INSTANCE), ImmutableList.<Projection>of(), DistributionInfo.DEFAULT_BROADCAST, null);
mergePhase.executionNodes(downstreamExecutionNodes);
NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0, "nodeName");
return rowDownstreamFactory.create(nodeOperation, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Aggregations