Search in sources :

Example 6 with RoutedCollectPhase

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

the class GroupByPlannerTest method testGroupByWithAggregationStringLiteralArguments.

@Test
public void testGroupByWithAggregationStringLiteralArguments() {
    Merge distributedGroupByMerge = e.plan("select count('foo'), name from users group by name");
    RoutedCollectPhase collectPhase = ((DistributedGroupBy) distributedGroupByMerge.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) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumnSorted.

@Test
public void testNonDistributedGroupByOnClusteredColumnSorted() throws Exception {
    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());
    assertThat(collectPhase.projections().size(), is(2));
    assertThat(collectPhase.projections().get(1), instanceOf(OrderedTopNProjection.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().size(), is(1));
    assertThat(mergePhase.projections().get(0), 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.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 8 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByAggregationsWrappedInScalar.

@Test
public void testNonDistributedGroupByAggregationsWrappedInScalar() throws Exception {
    Merge planNode = e.plan("select (count(*) + 1), id from empty_parted group by id");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) planNode.subPlan();
    RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class)));
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    MergePhase mergePhase = planNode.mergePhase();
    assertThat(mergePhase.projections().size(), is(0));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with RoutedCollectPhase

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

the class GroupByPlannerTest method testDistributedGroupByProjectionHasShardLevelGranularity.

@Test
public void testDistributedGroupByProjectionHasShardLevelGranularity() throws Exception {
    Merge distributedGroupByMerge = e.plan("select count(*) from users group by name");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
    RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
Also used : Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 10 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByProjectionHasShardLevelGranularity.

@Test
public void testNonDistributedGroupByProjectionHasShardLevelGranularity() throws Exception {
    Merge distributedGroupByMerge = e.plan("select count(distinct id), name from users" + " group by name order by count(distinct id)");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
    RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
Also used : Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)48 Test (org.junit.Test)36 CrateUnitTest (io.crate.test.integration.CrateUnitTest)25 Collect (io.crate.planner.node.dql.Collect)18 MergePhase (io.crate.planner.node.dql.MergePhase)15 Merge (io.crate.planner.Merge)14 Routing (io.crate.metadata.Routing)10 Symbol (io.crate.analyze.symbol.Symbol)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)7 Bucket (io.crate.data.Bucket)6 Reference (io.crate.metadata.Reference)6 Row (io.crate.data.Row)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3 CollectionBucket (io.crate.data.CollectionBucket)3