use of io.crate.planner.node.dql.MergePhase 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.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByWithHavingAndLimit.
@Test
public void testGroupByWithHavingAndLimit() throws Exception {
Merge planNode = e.plan("select count(*), name from users group by name having count(*) > 1 limit 100");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) planNode.subPlan();
// reducer
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
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: count(*), name
TopNProjection topN = (TopNProjection) mergePhase.projections().get(2);
assertThat(topN.outputs().get(0).valueType(), Is.<DataType>is(DataTypes.LONG));
assertThat(topN.outputs().get(1).valueType(), Is.<DataType>is(DataTypes.STRING));
MergePhase localMerge = planNode.mergePhase();
// topN projection
// outputs: count(*), name
topN = (TopNProjection) localMerge.projections().get(0);
assertThat(topN.outputs().get(0).valueType(), Is.<DataType>is(DataTypes.LONG));
assertThat(topN.outputs().get(1).valueType(), Is.<DataType>is(DataTypes.STRING));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByHaving.
@Test
public void testGroupByHaving() throws Exception {
Merge distributedGroupByMerge = e.plan("select avg(date), name from users group by name having min(date) > '1970-01-01'");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
assertThat(collectPhase.projections().size(), is(1));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
assertThat(mergePhase.projections().size(), is(3));
// grouping
assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
GroupProjection groupProjection = (GroupProjection) mergePhase.projections().get(0);
assertThat(groupProjection.values().size(), is(2));
// filter the having clause
assertThat(mergePhase.projections().get(1), instanceOf(FilterProjection.class));
FilterProjection filterProjection = (FilterProjection) mergePhase.projections().get(1);
assertThat(mergePhase.projections().get(2), instanceOf(EvalProjection.class));
EvalProjection eval = (EvalProjection) mergePhase.projections().get(2);
assertThat(eval.outputs().get(0).valueType(), Is.<DataType>is(DataTypes.DOUBLE));
assertThat(eval.outputs().get(1).valueType(), Is.<DataType>is(DataTypes.STRING));
}
use of io.crate.planner.node.dql.MergePhase in project crate by crate.
the class GroupByPlannerTest method testGroupByWithAggregationAndLimit.
@Test
public void testGroupByWithAggregationAndLimit() throws Exception {
Merge distributedGroupByMerge = e.plan("select count(*), name from users group by name limit 1 offset 1");
DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
// distributed merge
MergePhase distributedMergePhase = distributedGroupBy.reducerMergeNode();
assertThat(distributedMergePhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(distributedMergePhase.projections().get(1), instanceOf(TopNProjection.class));
// limit must include offset because the real limit can only be applied on the handler
// after all rows have been gathered.
TopNProjection topN = (TopNProjection) distributedMergePhase.projections().get(1);
assertThat(topN.limit(), is(2));
assertThat(topN.offset(), is(0));
// local merge
MergePhase localMergePhase = distributedGroupByMerge.mergePhase();
assertThat(localMergePhase.projections().get(0), instanceOf(TopNProjection.class));
topN = (TopNProjection) localMergePhase.projections().get(0);
assertThat(topN.limit(), is(1));
assertThat(topN.offset(), is(1));
assertThat(topN.outputs().get(0), instanceOf(InputColumn.class));
assertThat(((InputColumn) topN.outputs().get(0)).index(), is(0));
assertThat(topN.outputs().get(1), instanceOf(InputColumn.class));
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 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());
}
Aggregations