use of io.crate.planner.node.dql.RoutedCollectPhase 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.RoutedCollectPhase 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.RoutedCollectPhase 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));
}
use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class CopyToPlannerTest method testCopyToWithPartitionedGeneratedColumn.
@Test
public void testCopyToWithPartitionedGeneratedColumn() throws Exception {
// test that generated partition column is NOT exported
Merge plan = e.plan("copy parted_generated to directory '/tmp'");
Collect innerPlan = (Collect) plan.subPlan();
RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
WriterProjection projection = (WriterProjection) node.projections().get(0);
assertThat(projection.overwrites().size(), is(0));
}
use of io.crate.planner.node.dql.RoutedCollectPhase in project crate by crate.
the class CopyToPlannerTest method testCopyToWithColumnsReferenceRewrite.
@Test
public void testCopyToWithColumnsReferenceRewrite() throws Exception {
Merge plan = e.plan("copy users (name) to directory '/tmp'");
Collect innerPlan = (Collect) plan.subPlan();
RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
Reference nameRef = (Reference) node.toCollect().get(0);
assertThat(nameRef.ident().columnIdent().name(), is(DocSysColumns.DOC.name()));
assertThat(nameRef.ident().columnIdent().path().get(0), is("name"));
}
Aggregations