Search in sources :

Example 6 with MergePhase

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));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with MergePhase

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());
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with MergePhase

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());
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with MergePhase

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)));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with MergePhase

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)));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

MergePhase (io.crate.planner.node.dql.MergePhase)30 Test (org.junit.Test)27 CrateUnitTest (io.crate.test.integration.CrateUnitTest)26 Merge (io.crate.planner.Merge)15 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)15 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)13 Collect (io.crate.planner.node.dql.Collect)9 Reference (io.crate.metadata.Reference)3 Projection (io.crate.planner.projection.Projection)3 ImmutableList (com.google.common.collect.ImmutableList)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Routing (io.crate.metadata.Routing)2 NodeOperation (io.crate.operation.NodeOperation)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 PositionalOrderBy (io.crate.planner.PositionalOrderBy)2 Aggregation (io.crate.analyze.symbol.Aggregation)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 FunctionInfo (io.crate.metadata.FunctionInfo)1 ExecutionPhase (io.crate.planner.node.ExecutionPhase)1