Search in sources :

Example 1 with DistributedGroupBy

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

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

the class GroupByPlannerTest method testGroupByOrderByPartitionedClolumn.

@Test
public void testGroupByOrderByPartitionedClolumn() throws Exception {
    Merge plan = e.plan("select date from clustered_parted group by date order by date");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) plan.subPlan();
    OrderedTopNProjection topNProjection = (OrderedTopNProjection) distributedGroupBy.reducerMergeNode().projections().get(1);
    Symbol orderBy = topNProjection.orderBy().get(0);
    assertThat(orderBy, instanceOf(InputColumn.class));
    assertThat(orderBy.valueType(), is(DataTypes.TIMESTAMP));
}
Also used : Merge(io.crate.planner.Merge) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with DistributedGroupBy

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

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

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

DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)17 Test (org.junit.Test)17 Merge (io.crate.planner.Merge)14 MergePhase (io.crate.planner.node.dql.MergePhase)13 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)7 InputColumn (io.crate.analyze.symbol.InputColumn)1 Reference (io.crate.metadata.Reference)1 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)1 SymbolMatchers.isAggregation (io.crate.testing.SymbolMatchers.isAggregation)1 SymbolMatchers.isReference (io.crate.testing.SymbolMatchers.isReference)1