Search in sources :

Example 11 with Projection

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));
}
Also used : Collect(io.crate.planner.node.dql.Collect) OrderedTopNProjection(io.crate.execution.dsl.projection.OrderedTopNProjection) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) MergeCountProjection(io.crate.execution.dsl.projection.MergeCountProjection) GroupProjection(io.crate.execution.dsl.projection.GroupProjection) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) FetchProjection(io.crate.execution.dsl.projection.FetchProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 12 with Projection

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));
}
Also used : Collect(io.crate.planner.node.dql.Collect) FilterProjection(io.crate.execution.dsl.projection.FilterProjection) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 13 with Projection

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)));
}
Also used : QueryThenFetch(io.crate.planner.node.dql.QueryThenFetch) 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) AggregationProjection(io.crate.execution.dsl.projection.AggregationProjection) Projection(io.crate.execution.dsl.projection.Projection) TopNProjection(io.crate.execution.dsl.projection.TopNProjection) FetchProjection(io.crate.execution.dsl.projection.FetchProjection) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 14 with Projection

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());
}
Also used : Projection(io.crate.execution.dsl.projection.Projection)

Example 15 with Projection

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));
}
Also used : FilterProjection(io.crate.execution.dsl.projection.FilterProjection) MergePhase(io.crate.execution.dsl.phases.MergePhase) Merge(io.crate.planner.Merge) Symbol(io.crate.expression.symbol.Symbol) InputColumn(io.crate.expression.symbol.InputColumn) 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) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

Projection (io.crate.execution.dsl.projection.Projection)24 Test (org.junit.Test)16 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)15 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)14 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)14 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)13 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)12 Collect (io.crate.planner.node.dql.Collect)12 Symbol (io.crate.expression.symbol.Symbol)10 MergePhase (io.crate.execution.dsl.phases.MergePhase)9 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)8 InputColumn (io.crate.expression.symbol.InputColumn)8 AggregationProjection (io.crate.execution.dsl.projection.AggregationProjection)7 Merge (io.crate.planner.Merge)7 FetchProjection (io.crate.execution.dsl.projection.FetchProjection)5 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)4 QueryThenFetch (io.crate.planner.node.dql.QueryThenFetch)3 Join (io.crate.planner.node.dql.join.Join)3 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)2