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));
}
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)));
}
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));
}
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));
}
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));
}
Aggregations