Search in sources :

Example 11 with MergePhase

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

the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumnSorted.

@Test
public void testNonDistributedGroupByOnClusteredColumnSorted() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge merge = e.plan("select count(*), id from users group by id order by 1 desc nulls last limit 20");
    Collect collect = ((Collect) merge.subPlan());
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    List<Projection> collectProjections = collectPhase.projections();
    assertThat(collectProjections, contains(instanceOf(GroupProjection.class), instanceOf(OrderedTopNProjection.class), // swap id, count(*) -> count(*), id
    instanceOf(EvalProjection.class)));
    assertThat(collectProjections.get(1), instanceOf(OrderedTopNProjection.class));
    assertThat(((OrderedTopNProjection) collectProjections.get(1)).orderBy().size(), is(1));
    assertThat(collectProjections.get(0).requiredGranularity(), is(RowGranularity.SHARD));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(TopNProjection.class)));
    PositionalOrderBy positionalOrderBy = mergePhase.orderByPositions();
    assertThat(positionalOrderBy, notNullValue());
    assertThat(positionalOrderBy.indices().length, is(1));
    assertThat(positionalOrderBy.indices()[0], is(0));
    assertThat(positionalOrderBy.reverseFlags()[0], is(true));
    assertThat(positionalOrderBy.nullsFirst()[0], is(false));
}
Also used : PositionalOrderBy(io.crate.planner.PositionalOrderBy) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 12 with MergePhase

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

the class GroupByScalarPlannerTest method testGroupByWithMultipleScalarPlan.

@Test
public void testGroupByWithMultipleScalarPlan() throws Exception {
    Merge merge = e.plan("select abs(id + 1) from users group by id");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertEquals(DataTypes.LONG, collectPhase.outputTypes().get(0));
    assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
    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(EvalProjection.class));
    assertThat(collectPhase.projections().get(1).outputs().get(0), isFunction("abs"));
    assertThat(collectPhase.toCollect(), contains(isReference("id", DataTypes.LONG)));
    GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
    assertThat(groupProjection.keys().get(0).valueType(), is(DataTypes.LONG));
    MergePhase mergePhase = merge.mergePhase();
    assertEquals(DataTypes.LONG, mergePhase.inputTypes().iterator().next());
    assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 13 with MergePhase

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

the class GroupByScalarPlannerTest method testGroupByScalarWithMultipleColumnArgumentsPlan.

@Test
public void testGroupByScalarWithMultipleColumnArgumentsPlan() throws Exception {
    Merge merge = e.plan("select abs(id + other_id) from users group by id, other_id");
    Merge subplan = (Merge) merge.subPlan();
    Collect collect = (Collect) subplan.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
    assertThat(collectPhase.toCollect(), contains(isReference("id", DataTypes.LONG), isReference("other_id", DataTypes.LONG)));
    GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
    assertThat(groupProjection.keys().size(), is(2));
    assertThat(groupProjection.keys().get(0).valueType(), is(DataTypes.LONG));
    assertThat(groupProjection.keys().get(1).valueType(), is(DataTypes.LONG));
    MergePhase mergePhase = subplan.mergePhase();
    assertThat(mergePhase.projections().size(), is(2));
    assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
    assertThat(mergePhase.projections().get(1).outputs(), contains(isFunction("abs")));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 14 with MergePhase

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

the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByWithoutLimit.

@Test
public void testInsertFromSubQueryDistributedGroupByWithoutLimit() {
    Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name)");
    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(1));
    assertThat(projection.primaryKeys().get(0).fqn(), is("id"));
    assertThat(projection.columnReferencesExclPartition().size(), is(2));
    assertThat(projection.columnReferencesExclPartition().get(0).column().fqn(), is("id"));
    assertThat(projection.columnReferencesExclPartition().get(1).column().fqn(), is("name"));
    assertNotNull(projection.clusteredByIdent());
    assertThat(projection.clusteredByIdent().fqn(), is("id"));
    assertThat(projection.tableIdent().fqn(), is("doc.users"));
    assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
    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 15 with MergePhase

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

the class InsertPlannerTest method testInsertFromSubQueryGlobalAggregate.

@Test
public void testInsertFromSubQueryGlobalAggregate() {
    Merge globalAggregate = e.plan("insert into users (name, id) (select arbitrary(name), count(*) from users)");
    MergePhase mergePhase = globalAggregate.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(AggregationProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    assertThat(mergePhase.projections().get(1), instanceOf(ColumnIndexWriterProjection.class));
    ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(1);
    assertThat(projection.columnReferencesExclPartition().size(), is(2));
    assertThat(projection.columnReferencesExclPartition().get(0).column().fqn(), is("name"));
    assertThat(projection.columnReferencesExclPartition().get(1).column().fqn(), is("id"));
    assertThat(projection.columnSymbolsExclPartition().size(), is(2));
    assertThat(((InputColumn) projection.columnSymbolsExclPartition().get(0)).index(), is(0));
    assertThat(((InputColumn) projection.columnSymbolsExclPartition().get(1)).index(), is(1));
    assertNotNull(projection.clusteredByIdent());
    assertThat(projection.clusteredByIdent().fqn(), is("id"));
    assertThat(projection.tableIdent().fqn(), is("doc.users"));
    assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

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