Search in sources :

Example 16 with DistributedGroupBy

use of io.crate.planner.node.dql.DistributedGroupBy in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByPartitioned.

@Test
public void testInsertFromSubQueryDistributedGroupByPartitioned() throws Exception {
    Merge planNode = e.plan("insert into parted_pks (id, date) (select id, date from users group by id, date)");
    DistributedGroupBy groupBy = (DistributedGroupBy) planNode.subPlan();
    MergePhase mergePhase = groupBy.reducerMergeNode();
    assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(2);
    assertThat(projection.primaryKeys().size(), is(2));
    assertThat(projection.primaryKeys().get(0).fqn(), is("id"));
    assertThat(projection.primaryKeys().get(1).fqn(), is("date"));
    assertThat(projection.columnReferences().size(), is(1));
    assertThat(projection.columnReferences().get(0).ident().columnIdent().fqn(), is("id"));
    assertThat(projection.partitionedBySymbols().size(), is(1));
    assertThat(((InputColumn) projection.partitionedBySymbols().get(0)).index(), is(1));
    assertNotNull(projection.clusteredByIdent());
    assertThat(projection.clusteredByIdent().fqn(), is("id"));
    assertThat(projection.tableIdent().fqn(), is("doc.parted_pks"));
    MergePhase localMergeNode = planNode.mergePhase();
    assertThat(localMergeNode.projections().size(), is(1));
    assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
    assertThat(localMergeNode.finalProjection().get().outputs().size(), is(1));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 17 with DistributedGroupBy

use of io.crate.planner.node.dql.DistributedGroupBy in project crate by crate.

the class InsertPlannerTest method testGroupByHavingInsertInto.

@Test
public void testGroupByHavingInsertInto() throws Exception {
    Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name having count(*) > 3)");
    DistributedGroupBy groupByNode = (DistributedGroupBy) planNode.subPlan();
    MergePhase mergePhase = groupByNode.reducerMergeNode();
    assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    FilterProjection filterProjection = (FilterProjection) mergePhase.projections().get(1);
    assertThat(filterProjection.outputs().size(), is(2));
    assertThat(filterProjection.outputs().get(0), instanceOf(InputColumn.class));
    assertThat(filterProjection.outputs().get(1), instanceOf(InputColumn.class));
    InputColumn inputColumn = (InputColumn) filterProjection.outputs().get(0);
    assertThat(inputColumn.index(), is(0));
    inputColumn = (InputColumn) filterProjection.outputs().get(1);
    assertThat(inputColumn.index(), is(1));
    MergePhase localMergeNode = planNode.mergePhase();
    assertThat(localMergeNode.projections().size(), is(1));
    assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
    assertThat(localMergeNode.finalProjection().get().outputs().size(), is(1));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) InputColumn(io.crate.analyze.symbol.InputColumn) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Test (org.junit.Test)17 Merge (io.crate.planner.Merge)14 MergePhase (io.crate.planner.node.dql.MergePhase)13 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)7 InputColumn (io.crate.analyze.symbol.InputColumn)1 Reference (io.crate.metadata.Reference)1 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)1 SymbolMatchers.isAggregation (io.crate.testing.SymbolMatchers.isAggregation)1 SymbolMatchers.isReference (io.crate.testing.SymbolMatchers.isReference)1