use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByHavingAndNoSelectListReOrderingWithLimit.
@Test
public void testGroupByHavingAndNoSelectListReOrderingWithLimit() throws Exception {
Merge planNode = e.plan("select name, count(*) from users group by name having count(*) > 1 limit 100");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) planNode.subPlan();
// reducer
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
// group projection
// outputs: name, count(*)
// filter projection
// outputs: name, count(*)
// topN projection
// outputs: name, count(*)
Projection projection = mergePhase.projections().get(1);
assertThat(projection, instanceOf(FilterProjection.class));
FilterProjection filterProjection = (FilterProjection) projection;
Symbol countArgument = ((Function) filterProjection.query()).arguments().get(0);
assertThat(countArgument, instanceOf(InputColumn.class));
// pointing to second output from group projection
assertThat(((InputColumn) countArgument).index(), is(1));
// outputs: name, count(*)
assertThat(((InputColumn) filterProjection.outputs().get(0)).index(), is(0));
assertThat(((InputColumn) filterProjection.outputs().get(1)).index(), is(1));
// outputs: name, count(*)
TopNProjection topN = (TopNProjection) mergePhase.projections().get(2);
assertThat(((InputColumn) topN.outputs().get(0)).index(), is(0));
assertThat(((InputColumn) topN.outputs().get(1)).index(), is(1));
MergePhase localMerge = planNode.mergePhase();
// topN projection
// outputs: name, count(*)
topN = (TopNProjection) localMerge.projections().get(0);
assertThat(((InputColumn) topN.outputs().get(0)).index(), is(0));
assertThat(((InputColumn) topN.outputs().get(1)).index(), is(1));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByWithHavingAndNoSelectListReordering.
@Test
public void testGroupByWithHavingAndNoSelectListReordering() throws Exception {
Merge planNode = e.plan("select name, count(*) from users group by name having count(*) > 1");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) planNode.subPlan();
// reducer
MergePhase reducerMerge = distributedGroupBy.reducerMergeNode();
// group projection
// outputs: name, count(*)
// filter projection
// outputs: name, count(*)
assertThat(reducerMerge.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class), instanceOf(EvalProjection.class)));
Projection projection = reducerMerge.projections().get(1);
assertThat(projection, instanceOf(FilterProjection.class));
FilterProjection filterProjection = (FilterProjection) projection;
Symbol countArgument = ((Function) filterProjection.query()).arguments().get(0);
assertThat(countArgument, instanceOf(InputColumn.class));
// pointing to second output from group projection
assertThat(((InputColumn) countArgument).index(), is(1));
// outputs: name, count(*)
assertThat(((InputColumn) filterProjection.outputs().get(0)).index(), is(0));
assertThat(((InputColumn) filterProjection.outputs().get(1)).index(), is(1));
// eval projection
// outputs: name, count(*)
EvalProjection eval = (EvalProjection) reducerMerge.projections().get(2);
assertThat(((InputColumn) eval.outputs().get(0)).index(), is(0));
assertThat(((InputColumn) eval.outputs().get(1)).index(), is(1));
MergePhase localMerge = planNode.mergePhase();
assertThat(localMerge.projections(), empty());
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByWithAggregationPlan.
@Test
public void testGroupByWithAggregationPlan() throws Exception {
Merge distributedGroupByMerge = e.plan("select count(*), name from users group by name");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
// distributed collect
RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
assertThat(collectPhase.nodeIds().size(), is(2));
assertThat(collectPhase.toCollect().size(), is(1));
assertThat(collectPhase.projections().size(), is(1));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(collectPhase.outputTypes().size(), is(2));
assertEquals(DataTypes.STRING, collectPhase.outputTypes().get(0));
assertEquals(CountAggregation.LongStateType.INSTANCE, collectPhase.outputTypes().get(1));
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
assertThat(mergePhase.numUpstreams(), is(2));
assertThat(mergePhase.nodeIds().size(), is(2));
assertEquals(mergePhase.inputTypes(), collectPhase.outputTypes());
// for function evaluation and column-reordering there is always a EvalProjection
assertThat(mergePhase.projections().size(), is(2));
assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
GroupProjection groupProjection = (GroupProjection) mergePhase.projections().get(0);
InputColumn inputColumn = (InputColumn) groupProjection.values().get(0).inputs().get(0);
assertThat(inputColumn.index(), is(1));
assertThat(mergePhase.outputTypes().size(), is(2));
assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
assertEquals(DataTypes.STRING, mergePhase.outputTypes().get(1));
MergePhase localMerge = distributedGroupByMerge.mergePhase();
assertThat(localMerge.numUpstreams(), is(2));
assertThat(localMerge.nodeIds().size(), is(1));
assertThat(Iterables.getOnlyElement(localMerge.nodeIds()), is("noop_id"));
assertEquals(mergePhase.outputTypes(), localMerge.inputTypes());
assertThat(localMerge.projections(), empty());
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryNonDistributedGroupByWithCast.
@Test
public void testInsertFromSubQueryNonDistributedGroupByWithCast() throws Exception {
Merge nonDistributedGroupBy = e.plan("insert into users (id, name) (select name, count(*) 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 InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupByWithCast.
@Test
public void testInsertFromSubQueryReduceOnCollectorGroupByWithCast() throws Exception {
Merge merge = e.plan("insert into users (id, name) (select id, count(*) from users group by id)");
Collect nonDistributedGroupBy = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) nonDistributedGroupBy.collectPhase());
assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
EvalProjection collectTopN = (EvalProjection) collectPhase.projections().get(1);
assertThat(collectTopN.outputs(), contains(isInputColumn(0), isFunction("to_string")));
ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(2);
assertThat(columnIndexWriterProjection.columnReferences(), contains(isReference("id"), isReference("name")));
MergePhase mergePhase = merge.mergePhase();
assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Aggregations