use of io.crate.execution.dsl.phases.MergePhase 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));
}
use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.
the class GroupByScalarPlannerTest method testGroupByWithMultipleScalarPlan.
@Test
public void testGroupByWithMultipleScalarPlan() throws Exception {
Merge merge = e.plan("select abs(id + 1) from users group by id");
Collect collect = (Collect) merge.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertEquals(DataTypes.LONG, collectPhase.outputTypes().get(0));
assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
assertThat(collectPhase.projections().size(), is(2));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
assertThat(collectPhase.projections().get(1), instanceOf(EvalProjection.class));
assertThat(collectPhase.projections().get(1).outputs().get(0), isFunction("abs"));
assertThat(collectPhase.toCollect(), contains(isReference("id", DataTypes.LONG)));
GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
assertThat(groupProjection.keys().get(0).valueType(), is(DataTypes.LONG));
MergePhase mergePhase = merge.mergePhase();
assertEquals(DataTypes.LONG, mergePhase.inputTypes().iterator().next());
assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
}
use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.
the class GroupByScalarPlannerTest method testGroupByScalarWithMultipleColumnArgumentsPlan.
@Test
public void testGroupByScalarWithMultipleColumnArgumentsPlan() throws Exception {
Merge merge = e.plan("select abs(id + other_id) from users group by id, other_id");
Merge subplan = (Merge) merge.subPlan();
Collect collect = (Collect) subplan.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
assertThat(collectPhase.projections().size(), is(1));
assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
assertThat(collectPhase.toCollect(), contains(isReference("id", DataTypes.LONG), isReference("other_id", DataTypes.LONG)));
GroupProjection groupProjection = (GroupProjection) collectPhase.projections().get(0);
assertThat(groupProjection.keys().size(), is(2));
assertThat(groupProjection.keys().get(0).valueType(), is(DataTypes.LONG));
assertThat(groupProjection.keys().get(1).valueType(), is(DataTypes.LONG));
MergePhase mergePhase = subplan.mergePhase();
assertThat(mergePhase.projections().size(), is(2));
assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
assertThat(mergePhase.projections().get(1).outputs(), contains(isFunction("abs")));
}
use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryDistributedGroupByWithoutLimit.
@Test
public void testInsertFromSubQueryDistributedGroupByWithoutLimit() {
Merge planNode = e.plan("insert into users (id, name) (select name, count(*) from users group by name)");
Merge groupBy = (Merge) planNode.subPlan();
MergePhase mergePhase = groupBy.mergePhase();
assertThat(mergePhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(2);
assertThat(projection.primaryKeys().size(), is(1));
assertThat(projection.primaryKeys().get(0).fqn(), is("id"));
assertThat(projection.columnReferencesExclPartition().size(), is(2));
assertThat(projection.columnReferencesExclPartition().get(0).column().fqn(), is("id"));
assertThat(projection.columnReferencesExclPartition().get(1).column().fqn(), is("name"));
assertNotNull(projection.clusteredByIdent());
assertThat(projection.clusteredByIdent().fqn(), is("id"));
assertThat(projection.tableIdent().fqn(), is("doc.users"));
assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
MergePhase localMergeNode = planNode.mergePhase();
assertThat(localMergeNode.projections().size(), is(1));
assertThat(localMergeNode.projections().get(0), instanceOf(MergeCountProjection.class));
assertThat(localMergeNode.finalProjection().get().outputs().size(), is(1));
}
use of io.crate.execution.dsl.phases.MergePhase in project crate by crate.
the class InsertPlannerTest method testInsertFromSubQueryGlobalAggregate.
@Test
public void testInsertFromSubQueryGlobalAggregate() {
Merge globalAggregate = e.plan("insert into users (name, id) (select arbitrary(name), count(*) from users)");
MergePhase mergePhase = globalAggregate.mergePhase();
assertThat(mergePhase.projections(), contains(instanceOf(AggregationProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
assertThat(mergePhase.projections().get(1), instanceOf(ColumnIndexWriterProjection.class));
ColumnIndexWriterProjection projection = (ColumnIndexWriterProjection) mergePhase.projections().get(1);
assertThat(projection.columnReferencesExclPartition().size(), is(2));
assertThat(projection.columnReferencesExclPartition().get(0).column().fqn(), is("name"));
assertThat(projection.columnReferencesExclPartition().get(1).column().fqn(), is("id"));
assertThat(projection.columnSymbolsExclPartition().size(), is(2));
assertThat(((InputColumn) projection.columnSymbolsExclPartition().get(0)).index(), is(0));
assertThat(((InputColumn) projection.columnSymbolsExclPartition().get(1)).index(), is(1));
assertNotNull(projection.clusteredByIdent());
assertThat(projection.clusteredByIdent().fqn(), is("id"));
assertThat(projection.tableIdent().fqn(), is("doc.users"));
assertThat(projection.partitionedBySymbols().isEmpty(), is(true));
}
Aggregations