use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class UpdateConsumer method createPlan.
private static Plan createPlan(Planner.Context plannerContext, Routing routing, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause whereClause) {
RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), Collections.singletonList(idReference), Collections.singletonList(updateProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
use of io.crate.planner.node.dql.RoutedCollectPhase 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.RoutedCollectPhase in project crate by crate.
the class RoutedCollectPhaseTest method testStreaming.
@Test
public void testStreaming() throws Exception {
ImmutableList<Symbol> toCollect = ImmutableList.<Symbol>of(new Value(DataTypes.STRING));
UUID jobId = UUID.randomUUID();
RoutedCollectPhase cn = new RoutedCollectPhase(jobId, 0, "cn", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of()), RowGranularity.DOC, toCollect, ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
BytesStreamOutput out = new BytesStreamOutput();
cn.writeTo(out);
StreamInput in = StreamInput.wrap(out.bytes());
RoutedCollectPhase cn2 = RoutedCollectPhase.FACTORY.create();
cn2.readFrom(in);
assertThat(cn, equalTo(cn2));
assertThat(cn.toCollect(), is(cn2.toCollect()));
assertThat(cn.nodeIds(), is(cn2.nodeIds()));
assertThat(cn.jobId(), is(cn2.jobId()));
assertThat(cn.phaseId(), is(cn2.phaseId()));
assertThat(cn.maxRowGranularity(), is(cn2.maxRowGranularity()));
assertThat(cn.distributionInfo(), is(cn2.distributionInfo()));
}
use of io.crate.planner.node.dql.RoutedCollectPhase 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());
}
use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class GroupByPlannerTest method testNoDistributedGroupByOnAllPrimaryKeys.
@Test
public void testNoDistributedGroupByOnAllPrimaryKeys() throws Exception {
Merge merge = e.plan("select count(*), id, date from empty_parted group by id, date limit 20");
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections().size(), is(2));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
assertThat(collectPhase.projections().get(1), instanceOf(TopNProjection.class));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections().size(), is(1));
assertThat(mergePhase.projections().get(0), instanceOf(TopNProjection.class));
}
Aggregations