Search in sources :

Example 6 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumn.

@Test
public void testNonDistributedGroupByOnClusteredColumn() 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 limit 20");
    Collect collect = ((Collect) merge.subPlan());
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(TopNProjection.class), // swaps id, count(*) output from group by to count(*), id
    instanceOf(EvalProjection.class)));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(TopNProjection.class)));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 7 with RoutedCollectPhase

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

the class GroupByPlannerTest method testGroupByWithAggregationStringLiteralArguments.

@Test
public void testGroupByWithAggregationStringLiteralArguments() throws IOException {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select count('foo'), name from users group by name");
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) ((Collect) ((Merge) distributedGroupByMerge.subPlan()).subPlan()).collectPhase());
    assertThat(collectPhase.toCollect(), contains(isReference("name")));
    GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
    assertThat(groupProjection.values().get(0), isAggregation("count"));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 8 with RoutedCollectPhase

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

the class GroupByPlannerTest method testGroupByWithAggregationPlan.

@Test
public void testGroupByWithAggregationPlan() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select count(*), name from users group by name");
    Merge reducerMerge = (Merge) distributedGroupByMerge.subPlan();
    // distributed collect
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) ((Collect) reducerMerge.subPlan()).collectPhase());
    assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
    assertThat(collectPhase.nodeIds().size(), is(2));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.outputTypes().size(), is(2));
    assertEquals(DataTypes.STRING, collectPhase.outputTypes().get(0));
    assertEquals(CountAggregation.LongStateType.INSTANCE, collectPhase.outputTypes().get(1));
    MergePhase mergePhase = reducerMerge.mergePhase();
    assertThat(mergePhase.numUpstreams(), is(2));
    assertThat(mergePhase.nodeIds().size(), is(2));
    assertEquals(mergePhase.inputTypes(), collectPhase.outputTypes());
    // for function evaluation and column-reordering there is always a EvalProjection
    assertThat(mergePhase.projections().size(), is(2));
    assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
    assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
    GroupProjection groupProjection = (GroupProjection) mergePhase.projections().get(0);
    InputColumn inputColumn = (InputColumn) groupProjection.values().get(0).inputs().get(0);
    assertThat(inputColumn.index(), is(1));
    assertThat(mergePhase.outputTypes().size(), is(2));
    assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
    assertEquals(DataTypes.STRING, mergePhase.outputTypes().get(1));
    MergePhase localMerge = distributedGroupByMerge.mergePhase();
    assertThat(localMerge.numUpstreams(), is(2));
    assertThat(localMerge.nodeIds().size(), is(1));
    assertThat(localMerge.nodeIds().iterator().next(), is(NODE_ID));
    assertEquals(mergePhase.outputTypes(), localMerge.inputTypes());
    assertThat(localMerge.projections(), empty());
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) InputColumn(io.crate.expression.symbol.InputColumn) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 9 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumnSortedScalar.

@Test
public void testNonDistributedGroupByOnClusteredColumnSortedScalar() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge merge = e.plan("select count(*) + 1, id from users group by id order by count(*) + 1 limit 20");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(OrderedTopNProjection.class), instanceOf(EvalProjection.class)));
    assertThat(((OrderedTopNProjection) collectPhase.projections().get(1)).orderBy().size(), is(1));
    assertThat(collectPhase.projections().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(false));
    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) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 10 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase 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)

Aggregations

RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)50 Test (org.junit.Test)39 Collect (io.crate.planner.node.dql.Collect)23 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)23 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)18 Routing (io.crate.metadata.Routing)18 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Merge (io.crate.planner.Merge)10 Symbol (io.crate.expression.symbol.Symbol)9 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)7 ArrayList (java.util.ArrayList)6 Bucket (io.crate.data.Bucket)5 RelationName (io.crate.metadata.RelationName)5 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)3 OrderBy (io.crate.analyze.OrderBy)3