Search in sources :

Example 31 with MergePhase

use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryWithoutLimit.

@Test
public void testInsertFromSubQueryWithoutLimit() {
    Merge planNode = e.plan("insert into users (id, name) (select id, name from users)");
    Collect collect = (Collect) planNode.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(ColumnIndexWriterProjection.class));
    MergePhase localMergeNode = planNode.mergePhase();
    assertThat(localMergeNode.projections().size(), is(1));
    assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
}
Also used : MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 32 with MergePhase

use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupBy.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupBy() {
    Merge merge = e.plan("insert into users (id, name) (select id, arbitrary(name) from users group by id)");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(1);
    assertThat(columnIndexWriterProjection.columnReferencesExclPartition(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 33 with MergePhase

use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.

the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByPartitioned.

@Test
public void testInsertFromSubQueryDistributedGroupByPartitioned() {
    Merge planNode = e.plan("insert into parted_pks (id, date) (select id, date from users group by id, date)");
    Merge groupBy = (Merge) planNode.subPlan();
    MergePhase mergePhase = groupBy.mergePhase();
    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.columnReferencesExclPartition().size(), is(1));
    assertThat(projection.columnReferencesExclPartition().get(0).column().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 : MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 34 with MergePhase

use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.

the class InsertPlannerTest method testGroupByHavingInsertInto.

@Test
public void testGroupByHavingInsertInto() {
    Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name having count(*) > 3)");
    Merge groupByNode = (Merge) planNode.subPlan();
    MergePhase mergePhase = groupByNode.mergePhase();
    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 : MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) InputColumn(io.crate.expression.symbol.InputColumn) SymbolMatchers.isInputColumn(io.crate.testing.SymbolMatchers.isInputColumn) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 35 with MergePhase

use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.

the class UpdatePlannerTest method testUpdateByQueryPlan.

@Test
public void testUpdateByQueryPlan() throws Exception {
    UpdatePlanner.Update plan = e.plan("update users set name='Vogon lyric fan'");
    Merge merge = (Merge) plan.createExecutionPlan.create(e.getPlannerContext(clusterService.state()), Row.EMPTY, SubQueryResults.EMPTY);
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.where(), isSQL("true"));
    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)).column().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.execution.dsl.projection.MergeCountProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) InputColumn(io.crate.expression.symbol.InputColumn) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) UpdatePlanner(io.crate.planner.consumer.UpdatePlanner) UpdateProjection(io.crate.execution.dsl.projection.UpdateProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

MergePhase (io.crate.execution.dsl.phases.MergePhase)35 Test (org.junit.Test)26 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)24 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)17 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)16 Merge (io.crate.planner.Merge)15 Collect (io.crate.planner.node.dql.Collect)14 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)13 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)12 InputColumn (io.crate.expression.symbol.InputColumn)12 Symbol (io.crate.expression.symbol.Symbol)10 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)9 Projection (io.crate.execution.dsl.projection.Projection)9 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)9 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)8 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)6 MergeCountProjection (io.crate.execution.dsl.projection.MergeCountProjection)5 ExecutionPlan (io.crate.planner.ExecutionPlan)4 ResultDescription (io.crate.planner.ResultDescription)4 Routing (io.crate.metadata.Routing)3