Search in sources :

Example 11 with Collect

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

the class UpdatePlannerTest method testUpdateByQueryPlan.

@Test
public void testUpdateByQueryPlan() throws Exception {
    Upsert plan = e.plan("update users set name='Vogon lyric fan'");
    assertThat(plan.nodes().size(), is(1));
    Merge merge = (Merge) plan.nodes().get(0);
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.routing(), is(TableDefinitions.SHARD_ROUTING));
    assertFalse(collectPhase.whereClause().noMatch());
    assertFalse(collectPhase.whereClause().hasQuery());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(UpdateProjection.class));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
    assertThat(((Reference) collectPhase.toCollect().get(0)).ident().columnIdent().fqn(), is("_id"));
    UpdateProjection updateProjection = (UpdateProjection) collectPhase.projections().get(0);
    assertThat(updateProjection.uidSymbol(), instanceOf(InputColumn.class));
    assertThat(updateProjection.assignmentsColumns()[0], is("name"));
    Symbol symbol = updateProjection.assignments()[0];
    assertThat(symbol, isLiteral("Vogon lyric fan", DataTypes.STRING));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections().size(), is(1));
    assertThat(mergePhase.projections().get(0), instanceOf(MergeCountProjection.class));
    assertThat(mergePhase.outputTypes().size(), is(1));
}
Also used : MergeCountProjection(io.crate.planner.projection.MergeCountProjection) Upsert(io.crate.planner.node.dml.Upsert) MergePhase(io.crate.planner.node.dql.MergePhase) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) Symbol(io.crate.analyze.symbol.Symbol) UpdateProjection(io.crate.planner.projection.UpdateProjection) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 12 with Collect

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

the class GroupByPlannerTest method testGroupByOnClusteredByColumnPartitionedOnePartition.

@Test
public void testGroupByOnClusteredByColumnPartitionedOnePartition() throws Exception {
    // only one partition hit
    Merge optimizedPlan = e.plan("select count(*), city from clustered_parted where date=1395874800000 group by city");
    Collect collect = (Collect) optimizedPlan.subPlan();
    assertThat(collect.collectPhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
    assertThat(collect.collectPhase().projections().get(0), instanceOf(GroupProjection.class));
    assertThat(optimizedPlan.mergePhase().projections().size(), is(0));
    // > 1 partition hit
    Plan plan = e.plan("select count(*), city from clustered_parted where date=1395874800000 or date=1395961200000 group by city");
    assertThat(plan, instanceOf(Merge.class));
    assertThat(((Merge) plan).subPlan(), instanceOf(DistributedGroupBy.class));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Plan(io.crate.planner.Plan) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with Collect

use of io.crate.planner.node.dql.Collect 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));
}
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 14 with Collect

use of io.crate.planner.node.dql.Collect 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 15 with Collect

use of io.crate.planner.node.dql.Collect 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)

Aggregations

Collect (io.crate.planner.node.dql.Collect)21 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)18 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Test (org.junit.Test)17 MergePhase (io.crate.planner.node.dql.MergePhase)9 Merge (io.crate.planner.Merge)8 Reference (io.crate.metadata.Reference)6 Symbol (io.crate.analyze.symbol.Symbol)3 InputColumn (io.crate.analyze.symbol.InputColumn)2 PositionalOrderBy (io.crate.planner.PositionalOrderBy)2 DeleteProjection (io.crate.planner.projection.DeleteProjection)2 MergeCountProjection (io.crate.planner.projection.MergeCountProjection)2 Projection (io.crate.planner.projection.Projection)2 WriterProjection (io.crate.planner.projection.WriterProjection)2 Function (io.crate.analyze.symbol.Function)1 ColumnIdent (io.crate.metadata.ColumnIdent)1 GeneratedReference (io.crate.metadata.GeneratedReference)1 ReferenceIdent (io.crate.metadata.ReferenceIdent)1 Routing (io.crate.metadata.Routing)1 DocTableInfo (io.crate.metadata.doc.DocTableInfo)1