Search in sources :

Example 1 with CollectPhase

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

the class GroupByPlannerTest method testDistributedGroupByProjectionHasShardLevelGranularity.

@Test
public void testDistributedGroupByProjectionHasShardLevelGranularity() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select count(*) from users group by name");
    Merge reduceMerge = (Merge) distributedGroupByMerge.subPlan();
    CollectPhase collectPhase = ((Collect) reduceMerge.subPlan()).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) Collect(io.crate.planner.node.dql.Collect) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 2 with CollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByAggregationsWrappedInScalar.

@Test
public void testNonDistributedGroupByAggregationsWrappedInScalar() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addPartitionedTable("create table doc.empty_parted (" + "   id integer primary key," + "   date timestamp with time zone primary key" + ") clustered by (id) partitioned by (date)").build();
    Collect collect = e.plan("select (count(*) + 1), id from empty_parted group by id");
    CollectPhase collectPhase = collect.collectPhase();
    assertThat(collectPhase.projections(), contains(// shard level
    instanceOf(GroupProjection.class), // node level
    instanceOf(GroupProjection.class), // count(*) + 1
    instanceOf(EvalProjection.class)));
}
Also used : Collect(io.crate.planner.node.dql.Collect) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 3 with CollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByProjectionHasShardLevelGranularity.

@Test
public void testNonDistributedGroupByProjectionHasShardLevelGranularity() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select count(distinct id), name from users" + " group by name order by count(distinct id)");
    Merge reduceMerge = (Merge) distributedGroupByMerge.subPlan();
    CollectPhase collectPhase = ((Collect) reduceMerge.subPlan()).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) Collect(io.crate.planner.node.dql.Collect) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 4 with CollectPhase

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

the class GroupByPlannerTest method testNestedGroupByAggregation.

@Test
public void testNestedGroupByAggregation() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).build();
    Collect collect = e.plan("select count(*) from (" + "  select max(load['1']) as maxLoad, hostname " + "  from sys.nodes " + "  group by hostname having max(load['1']) > 50) as nodes " + "group by hostname");
    assertThat("would require merge if more than 1 nodeIds", collect.nodeIds().size(), is(1));
    CollectPhase collectPhase = collect.collectPhase();
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(FilterProjection.class), instanceOf(EvalProjection.class), instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
    Projection firstGroupProjection = collectPhase.projections().get(0);
    assertThat(((GroupProjection) firstGroupProjection).mode(), is(AggregateMode.ITER_FINAL));
    Projection secondGroupProjection = collectPhase.projections().get(3);
    assertThat(((GroupProjection) secondGroupProjection).mode(), is(AggregateMode.ITER_FINAL));
}
Also used : 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) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 5 with CollectPhase

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

the class GroupByPlannerTest method testGroupByHaving.

@Test
public void testGroupByHaving() throws Exception {
    var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
    Merge distributedGroupByMerge = e.plan("select avg(date), name from users group by name having min(date) > '1970-01-01'");
    Merge reduceMerge = (Merge) distributedGroupByMerge.subPlan();
    CollectPhase collectPhase = ((Collect) reduceMerge.subPlan()).collectPhase();
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    MergePhase reducePhase = reduceMerge.mergePhase();
    assertThat(reducePhase.projections().size(), is(3));
    // grouping
    assertThat(reducePhase.projections().get(0), instanceOf(GroupProjection.class));
    GroupProjection groupProjection = (GroupProjection) reducePhase.projections().get(0);
    assertThat(groupProjection.values().size(), is(2));
    // filter the having clause
    assertThat(reducePhase.projections().get(1), instanceOf(FilterProjection.class));
    FilterProjection filterProjection = (FilterProjection) reducePhase.projections().get(1);
    assertThat(reducePhase.projections().get(2), instanceOf(EvalProjection.class));
    EvalProjection eval = (EvalProjection) reducePhase.projections().get(2);
    assertThat(eval.outputs().get(0).valueType(), Is.<DataType>is(DataTypes.DOUBLE));
    assertThat(eval.outputs().get(1).valueType(), Is.<DataType>is(DataTypes.STRING));
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) 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) CollectPhase(io.crate.execution.dsl.phases.CollectPhase) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

CollectPhase (io.crate.execution.dsl.phases.CollectPhase)10 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)10 Collect (io.crate.planner.node.dql.Collect)8 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)8 Test (org.junit.Test)8 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)6 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)5 Merge (io.crate.planner.Merge)4 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)3 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)3 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)2 Iterables (io.crate.common.collections.Iterables)2 BatchIterator (io.crate.data.BatchIterator)2 Row (io.crate.data.Row)2 MergePhase (io.crate.execution.dsl.phases.MergePhase)2 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)2 Projection (io.crate.execution.dsl.projection.Projection)2 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)2 CollectTask (io.crate.execution.engine.collect.CollectTask)2 RowsTransformer (io.crate.execution.engine.collect.RowsTransformer)2