Search in sources :

Example 31 with Collect

use of io.crate.planner.node.dql.Collect 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 32 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class GlobalAggregateConsumer method globalAggregates.

/**
     * Create a Merge(Collect) plan.
     *
     * iter->partial aggregations on use {@code projectionGranularity} granularity
     */
private static Plan globalAggregates(Functions functions, QueriedTableRelation table, ConsumerContext context, RowGranularity projectionGranularity) {
    QuerySpec querySpec = table.querySpec();
    if (querySpec.groupBy().isPresent() || !querySpec.hasAggregates()) {
        return null;
    }
    // global aggregate: collect and partial aggregate on C and final agg on H
    Planner.Context plannerContext = context.plannerContext();
    validateAggregationOutputs(table.tableRelation(), querySpec.outputs());
    ProjectionBuilder projectionBuilder = new ProjectionBuilder(functions, querySpec);
    SplitPoints splitPoints = projectionBuilder.getSplitPoints();
    AggregationProjection ap = projectionBuilder.aggregationProjection(splitPoints.leaves(), splitPoints.aggregates(), Aggregation.Step.ITER, Aggregation.Step.PARTIAL, projectionGranularity);
    RoutedCollectPhase collectPhase = RoutedCollectPhase.forQueriedTable(plannerContext, table, splitPoints.leaves(), ImmutableList.of(ap));
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, ap.outputs().size(), 1, null);
    AggregationProjection aggregationProjection = projectionBuilder.aggregationProjection(splitPoints.aggregates(), splitPoints.aggregates(), Aggregation.Step.PARTIAL, Aggregation.Step.FINAL, RowGranularity.CLUSTER);
    List<Projection> postAggregationProjections = createPostAggregationProjections(querySpec, splitPoints, plannerContext);
    postAggregationProjections.add(0, aggregationProjection);
    return createMerge(collect, plannerContext, postAggregationProjections);
}
Also used : Collect(io.crate.planner.node.dql.Collect) SplitPoints(io.crate.planner.projection.builder.SplitPoints) FilterProjection(io.crate.planner.projection.FilterProjection) AggregationProjection(io.crate.planner.projection.AggregationProjection) Projection(io.crate.planner.projection.Projection) ProjectionBuilder(io.crate.planner.projection.builder.ProjectionBuilder) AggregationProjection(io.crate.planner.projection.AggregationProjection) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 33 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class UpdateConsumer method createPlan.

private static Plan createPlan(Planner.Context plannerContext, Routing routing, TableInfo tableInfo, Reference idReference, Projection updateProjection, WhereClause whereClause) {
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), Collections.singletonList(idReference), Collections.singletonList(updateProjection), whereClause, DistributionInfo.DEFAULT_BROADCAST);
    Collect collect = new Collect(collectPhase, TopN.NO_LIMIT, 0, 1, 1, null);
    return Merge.ensureOnHandler(collect, plannerContext, Collections.singletonList(MergeCountProjection.INSTANCE));
}
Also used : Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 34 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class CopyToPlannerTest method testCopyToWithPartitionedGeneratedColumn.

@Test
public void testCopyToWithPartitionedGeneratedColumn() throws Exception {
    // test that generated partition column is NOT exported
    Merge plan = e.plan("copy parted_generated to directory '/tmp'");
    Collect innerPlan = (Collect) plan.subPlan();
    RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
    WriterProjection projection = (WriterProjection) node.projections().get(0);
    assertThat(projection.overwrites().size(), is(0));
}
Also used : WriterProjection(io.crate.planner.projection.WriterProjection) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 35 with Collect

use of io.crate.planner.node.dql.Collect in project crate by crate.

the class CopyToPlannerTest method testCopyToWithColumnsReferenceRewrite.

@Test
public void testCopyToWithColumnsReferenceRewrite() throws Exception {
    Merge plan = e.plan("copy users (name) to directory '/tmp'");
    Collect innerPlan = (Collect) plan.subPlan();
    RoutedCollectPhase node = ((RoutedCollectPhase) innerPlan.collectPhase());
    Reference nameRef = (Reference) node.toCollect().get(0);
    assertThat(nameRef.ident().columnIdent().name(), is(DocSysColumns.DOC.name()));
    assertThat(nameRef.ident().columnIdent().path().get(0), is("name"));
}
Also used : Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Collect (io.crate.planner.node.dql.Collect)66 Test (org.junit.Test)57 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)55 RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)31 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)27 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)18 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)16 Merge (io.crate.planner.Merge)16 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Projection (io.crate.execution.dsl.projection.Projection)12 Reference (io.crate.metadata.Reference)11 FilterProjection (io.crate.execution.dsl.projection.FilterProjection)10 TopNProjection (io.crate.execution.dsl.projection.TopNProjection)10 OrderedTopNProjection (io.crate.execution.dsl.projection.OrderedTopNProjection)9 CollectPhase (io.crate.execution.dsl.phases.CollectPhase)8 Symbol (io.crate.expression.symbol.Symbol)8 AggregationProjection (io.crate.execution.dsl.projection.AggregationProjection)6 QueryThenFetch (io.crate.planner.node.dql.QueryThenFetch)6 ColumnIndexWriterProjection (io.crate.execution.dsl.projection.ColumnIndexWriterProjection)5 InputColumn (io.crate.expression.symbol.InputColumn)5