use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class InsertPlannerTest method test_insert_select_distinct.
@Test
public void test_insert_select_distinct() throws Exception {
Merge merge = e.plan("insert into users (id) (select distinct id from users)");
Collect collect = (Collect) merge.subPlan();
List<Projection> projections = collect.collectPhase().projections();
assertThat(projections, contains(instanceOf(GroupProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
assertThat(projections.get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class GlobalAggregatePlannerTest method test_aggregate_on_virtual_table_uses_shard_projections_if_possible.
@Test
public void test_aggregate_on_virtual_table_uses_shard_projections_if_possible() {
Collect plan = e.plan("select sum(x) from (select x from t1) t");
List<Projection> projections = plan.collectPhase().projections();
assertThat(projections, contains(instanceOf(AggregationProjection.class), instanceOf(AggregationProjection.class)));
assertThat(projections.get(0).requiredGranularity(), is(RowGranularity.SHARD));
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class SubQueryPlannerTest method testNestedSimpleSelectContainsFilterProjectionForWhereClause.
@Test
public void testNestedSimpleSelectContainsFilterProjectionForWhereClause() throws Exception {
QueryThenFetch qtf = e.plan("select x, i from " + " (select x, i from t1 order by x asc limit 10) ti " + "where ti.x = 10 " + "order by x desc limit 3");
Collect collect = (Collect) qtf.subPlan();
List<Projection> projections = collect.collectPhase().projections();
assertThat(projections, Matchers.hasItem(instanceOf(FilterProjection.class)));
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class Collect method streamOutputs.
@Override
public List<DataType<?>> streamOutputs() {
List<Projection> projections = collectPhase.projections();
if (projections.isEmpty()) {
return Symbols.typeView(collectPhase.toCollect());
}
Projection lastProjection = projections.get(projections.size() - 1);
return Symbols.typeView(lastProjection.outputs());
}
use of io.crate.execution.dsl.projection.Projection in project crate by crate.
the class GroupByPlannerTest method testGroupByWithHavingAndNoLimit.
@Test
public void testGroupByWithHavingAndNoLimit() throws Exception {
var e = SQLExecutor.builder(clusterService, 2, RandomizedTest.getRandom(), List.of()).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
Merge planNode = e.plan("select count(*), name from users group by name having count(*) > 1");
Merge reducerMerge = (Merge) planNode.subPlan();
// reducer
MergePhase mergePhase = reducerMerge.mergePhase();
// group projection
// outputs: name, count(*)
Projection projection = mergePhase.projections().get(1);
assertThat(projection, instanceOf(FilterProjection.class));
FilterProjection filterProjection = (FilterProjection) projection;
Symbol countArgument = ((Function) filterProjection.query()).arguments().get(0);
assertThat(countArgument, instanceOf(InputColumn.class));
// pointing to second output from group projection
assertThat(((InputColumn) countArgument).index(), is(1));
assertThat(mergePhase.outputTypes().get(0), equalTo(DataTypes.LONG));
assertThat(mergePhase.outputTypes().get(1), equalTo(DataTypes.STRING));
mergePhase = planNode.mergePhase();
assertThat(mergePhase.outputTypes().get(0), equalTo(DataTypes.LONG));
assertThat(mergePhase.outputTypes().get(1), equalTo(DataTypes.STRING));
}
Aggregations