Search in sources :

Example 36 with RoutedCollectPhase

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));
}
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 37 with RoutedCollectPhase

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

Example 38 with RoutedCollectPhase

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));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) SymbolMatchers.isAggregation(io.crate.testing.SymbolMatchers.isAggregation) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 39 with RoutedCollectPhase

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

Example 40 with RoutedCollectPhase

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

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)48 Test (org.junit.Test)36 CrateUnitTest (io.crate.test.integration.CrateUnitTest)25 Collect (io.crate.planner.node.dql.Collect)18 MergePhase (io.crate.planner.node.dql.MergePhase)15 Merge (io.crate.planner.Merge)14 Routing (io.crate.metadata.Routing)10 Symbol (io.crate.analyze.symbol.Symbol)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)7 Bucket (io.crate.data.Bucket)6 Reference (io.crate.metadata.Reference)6 Row (io.crate.data.Row)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3 CollectionBucket (io.crate.data.CollectionBucket)3