use of io.crate.planner.node.dql.Collect 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.Collect in project crate by crate.
the class GroupByPlannerTest method testGroupByOnClusteredByColumnPartitionedOnePartition.
@Test
public void testGroupByOnClusteredByColumnPartitionedOnePartition() throws Exception {
// 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
Plan plan = e.plan("select count(*), city from clustered_parted where date=1395874800000 or date=1395961200000 group by city");
assertThat(plan, instanceOf(Merge.class));
assertThat(((Merge) plan).subPlan(), instanceOf(DistributedGroupBy.class));
}
use of io.crate.planner.node.dql.Collect 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));
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class GroupByPlannerTest method testGroupByHavingNonDistributed.
@Test
public void testGroupByHavingNonDistributed() throws Exception {
Merge merge = e.plan("select id from users group by id having id > 0");
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class), instanceOf(EvalProjection.class)));
FilterProjection filterProjection = (FilterProjection) collectPhase.projections().get(1);
assertThat(filterProjection.requiredGranularity(), is(RowGranularity.SHARD));
assertThat(filterProjection.outputs().size(), is(1));
assertThat(filterProjection.outputs().get(0), instanceOf(InputColumn.class));
InputColumn inputColumn = (InputColumn) filterProjection.outputs().get(0);
assertThat(inputColumn.index(), is(0));
MergePhase localMergeNode = merge.mergePhase();
assertThat(localMergeNode.projections(), empty());
}
use of io.crate.planner.node.dql.Collect in project crate by crate.
the class GroupByPlannerTest method testGroupByOnNodeLevel.
@Test
public void testGroupByOnNodeLevel() throws Exception {
Merge merge = e.plan("select count(*), name from sys.nodes group by name");
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class)));
assertThat(merge.resultDescription().streamOutputs(), contains(is(DataTypes.LONG), is(DataTypes.STRING)));
GroupProjection firstGroupProjection = (GroupProjection) collectPhase.projections().get(0);
assertThat(firstGroupProjection.keys().size(), is(1));
assertThat(((InputColumn) firstGroupProjection.outputs().get(0)).index(), is(0));
assertThat(firstGroupProjection.outputs().get(1), is(instanceOf(Aggregation.class)));
assertThat(((Aggregation) firstGroupProjection.outputs().get(1)).functionIdent().name(), is("count"));
assertThat(((Aggregation) firstGroupProjection.outputs().get(1)).fromStep(), is(Aggregation.Step.ITER));
assertThat(((Aggregation) firstGroupProjection.outputs().get(1)).toStep(), is(Aggregation.Step.PARTIAL));
assertThat(merge.mergePhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
Projection secondGroupProjection = merge.mergePhase().projections().get(0);
assertThat(((Aggregation) secondGroupProjection.outputs().get(1)).fromStep(), is(Aggregation.Step.PARTIAL));
assertThat(((Aggregation) secondGroupProjection.outputs().get(1)).toStep(), is(Aggregation.Step.FINAL));
}
Aggregations