use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GlobalAggregateConsumer method createMerge.
private static Plan createMerge(Plan plan, Planner.Context plannerContext, List<Projection> mergeProjections) {
ResultDescription resultDescription = plan.resultDescription();
MergePhase mergePhase = new MergePhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "mergeOnHandler", resultDescription.nodeIds().size(), Collections.singletonList(plannerContext.handlerNode()), resultDescription.streamOutputs(), mergeProjections, DistributionInfo.DEFAULT_SAME_NODE, null);
Projection lastProjection = mergeProjections.get(mergeProjections.size() - 1);
return new Merge(plan, mergePhase, TopN.NO_LIMIT, 0, lastProjection.outputs().size(), 1, null);
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class UpdatePlannerTest method testUpdateByQueryPlan.
@Test
public void testUpdateByQueryPlan() throws Exception {
Upsert plan = e.plan("update users set name='Vogon lyric fan'");
assertThat(plan.nodes().size(), is(1));
Merge merge = (Merge) plan.nodes().get(0);
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.routing(), is(TableDefinitions.SHARD_ROUTING));
assertFalse(collectPhase.whereClause().noMatch());
assertFalse(collectPhase.whereClause().hasQuery());
assertThat(collectPhase.projections().size(), is(1));
assertThat(collectPhase.projections().get(0), instanceOf(UpdateProjection.class));
assertThat(collectPhase.toCollect().size(), is(1));
assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
assertThat(((Reference) collectPhase.toCollect().get(0)).ident().columnIdent().fqn(), is("_id"));
UpdateProjection updateProjection = (UpdateProjection) collectPhase.projections().get(0);
assertThat(updateProjection.uidSymbol(), instanceOf(InputColumn.class));
assertThat(updateProjection.assignmentsColumns()[0], is("name"));
Symbol symbol = updateProjection.assignments()[0];
assertThat(symbol, isLiteral("Vogon lyric fan", DataTypes.STRING));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections().size(), is(1));
assertThat(mergePhase.projections().get(0), instanceOf(MergeCountProjection.class));
assertThat(mergePhase.outputTypes().size(), is(1));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByWithOrderOnAggregate.
@Test
public void testGroupByWithOrderOnAggregate() throws Exception {
Merge merge = e.plan("select count(*), name from users group by name order by count(*)");
assertThat(merge.mergePhase().orderByPositions(), notNullValue());
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) merge.subPlan();
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(OrderedTopNProjection.class)));
OrderedTopNProjection topNProjection = (OrderedTopNProjection) mergePhase.projections().get(1);
Symbol orderBy = topNProjection.orderBy().get(0);
assertThat(orderBy, instanceOf(InputColumn.class));
assertThat(orderBy.valueType(), Is.<DataType>is(DataTypes.LONG));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class MergeNodeTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Reference nameRef = TestingHelpers.createReference("name", DataTypes.STRING);
List<Symbol> keys = Collections.singletonList(nameRef);
List<Aggregation> aggregations = Collections.singletonList(Aggregation.finalAggregation(new FunctionInfo(new FunctionIdent(CountAggregation.NAME, ImmutableList.of()), DataTypes.LONG), ImmutableList.of(), Aggregation.Step.PARTIAL));
GroupProjection groupProjection = new GroupProjection(keys, aggregations, RowGranularity.CLUSTER);
TopNProjection topNProjection = new TopNProjection(10, 0, InputColumn.numInputs(keys.size() + aggregations.size()));
List<Projection> projections = Arrays.asList(groupProjection, topNProjection);
MergePhase node = new MergePhase(UUID.randomUUID(), 0, "merge", 2, Collections.emptyList(), Arrays.<DataType>asList(DataTypes.UNDEFINED, DataTypes.STRING), projections, DistributionInfo.DEFAULT_BROADCAST, null);
node.executionNodes(Sets.newHashSet("node1", "node2"));
BytesStreamOutput output = new BytesStreamOutput();
node.writeTo(output);
StreamInput input = StreamInput.wrap(output.bytes());
MergePhase node2 = MergePhase.FACTORY.create();
node2.readFrom(input);
assertThat(node.numUpstreams(), is(node2.numUpstreams()));
assertThat(node.nodeIds(), is(node2.nodeIds()));
assertThat(node.jobId(), is(node2.jobId()));
assertEquals(node.inputTypes(), node2.inputTypes());
assertThat(node.phaseId(), is(node2.phaseId()));
assertThat(node.distributionInfo(), is(node2.distributionInfo()));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testCountDistinctWithGroupBy.
@Test
public void testCountDistinctWithGroupBy() throws Exception {
Merge distributedGroupByMerge = e.plan("select count(distinct id), name from users group by name order by count(distinct id)");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
// collect
assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
assertThat(collectPhase.toCollect().size(), is(2));
assertThat(((Reference) collectPhase.toCollect().get(0)).ident().columnIdent().name(), is("id"));
assertThat(((Reference) collectPhase.toCollect().get(1)).ident().columnIdent().name(), is("name"));
Projection projection = collectPhase.projections().get(0);
assertThat(projection, instanceOf(GroupProjection.class));
GroupProjection groupProjection = (GroupProjection) projection;
Symbol groupKey = groupProjection.keys().get(0);
assertThat(groupKey, instanceOf(InputColumn.class));
assertThat(((InputColumn) groupKey).index(), is(1));
assertThat(groupProjection.values().size(), is(1));
Aggregation aggregation = groupProjection.values().get(0);
assertThat(aggregation.toStep(), is(Aggregation.Step.PARTIAL));
Symbol aggregationInput = aggregation.inputs().get(0);
assertThat(aggregationInput.symbolType(), is(SymbolType.INPUT_COLUMN));
// reducer
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
assertThat(mergePhase.projections().size(), is(2));
Projection groupProjection1 = mergePhase.projections().get(0);
assertThat(groupProjection1, instanceOf(GroupProjection.class));
groupProjection = (GroupProjection) groupProjection1;
assertThat(groupProjection.keys().get(0), instanceOf(InputColumn.class));
assertThat(((InputColumn) groupProjection.keys().get(0)).index(), is(0));
assertThat(groupProjection.values().get(0), instanceOf(Aggregation.class));
Aggregation aggregationStep2 = groupProjection.values().get(0);
assertThat(aggregationStep2.toStep(), is(Aggregation.Step.FINAL));
OrderedTopNProjection topNProjection = (OrderedTopNProjection) mergePhase.projections().get(1);
Symbol collection_count = topNProjection.outputs().get(0);
assertThat(collection_count, instanceOf(Function.class));
// handler
MergePhase localMergeNode = distributedGroupByMerge.mergePhase();
assertThat(localMergeNode.projections(), empty());
}
Aggregations