Search in sources :

Example 31 with RoutedCollectPhase

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

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

the class UpdatePlannerTest method testUpdateByQueryPlan.

@Test
public void testUpdateByQueryPlan() throws Exception {
    Upsert plan = e.plan("update users set name='Vogon lyric fan'");
    assertThat(plan.nodes().size(), is(1));
    Merge merge = (Merge) plan.nodes().get(0);
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.routing(), is(TableDefinitions.SHARD_ROUTING));
    assertFalse(collectPhase.whereClause().noMatch());
    assertFalse(collectPhase.whereClause().hasQuery());
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(UpdateProjection.class));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
    assertThat(((Reference) collectPhase.toCollect().get(0)).ident().columnIdent().fqn(), is("_id"));
    UpdateProjection updateProjection = (UpdateProjection) collectPhase.projections().get(0);
    assertThat(updateProjection.uidSymbol(), instanceOf(InputColumn.class));
    assertThat(updateProjection.assignmentsColumns()[0], is("name"));
    Symbol symbol = updateProjection.assignments()[0];
    assertThat(symbol, isLiteral("Vogon lyric fan", DataTypes.STRING));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections().size(), is(1));
    assertThat(mergePhase.projections().get(0), instanceOf(MergeCountProjection.class));
    assertThat(mergePhase.outputTypes().size(), is(1));
}
Also used : MergeCountProjection(io.crate.planner.projection.MergeCountProjection) Upsert(io.crate.planner.node.dml.Upsert) MergePhase(io.crate.planner.node.dql.MergePhase) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) Symbol(io.crate.analyze.symbol.Symbol) UpdateProjection(io.crate.planner.projection.UpdateProjection) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 33 with RoutedCollectPhase

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

the class RoutedCollectPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    ImmutableList<Symbol> toCollect = ImmutableList.<Symbol>of(new Value(DataTypes.STRING));
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase cn = new RoutedCollectPhase(jobId, 0, "cn", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of()), RowGranularity.DOC, toCollect, ImmutableList.<Projection>of(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_MODULO);
    BytesStreamOutput out = new BytesStreamOutput();
    cn.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    RoutedCollectPhase cn2 = RoutedCollectPhase.FACTORY.create();
    cn2.readFrom(in);
    assertThat(cn, equalTo(cn2));
    assertThat(cn.toCollect(), is(cn2.toCollect()));
    assertThat(cn.nodeIds(), is(cn2.nodeIds()));
    assertThat(cn.jobId(), is(cn2.jobId()));
    assertThat(cn.phaseId(), is(cn2.phaseId()));
    assertThat(cn.maxRowGranularity(), is(cn2.maxRowGranularity()));
    assertThat(cn.distributionInfo(), is(cn2.distributionInfo()));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Value(io.crate.analyze.symbol.Value) StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 34 with RoutedCollectPhase

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

the class GroupByPlannerTest method testCountDistinctWithGroupBy.

@Test
public void testCountDistinctWithGroupBy() throws Exception {
    Merge distributedGroupByMerge = e.plan("select count(distinct id), name from users group by name order by count(distinct id)");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
    RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
    // collect
    assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
    assertThat(collectPhase.toCollect().size(), is(2));
    assertThat(((Reference) collectPhase.toCollect().get(0)).ident().columnIdent().name(), is("id"));
    assertThat(((Reference) collectPhase.toCollect().get(1)).ident().columnIdent().name(), is("name"));
    Projection projection = collectPhase.projections().get(0);
    assertThat(projection, instanceOf(GroupProjection.class));
    GroupProjection groupProjection = (GroupProjection) projection;
    Symbol groupKey = groupProjection.keys().get(0);
    assertThat(groupKey, instanceOf(InputColumn.class));
    assertThat(((InputColumn) groupKey).index(), is(1));
    assertThat(groupProjection.values().size(), is(1));
    Aggregation aggregation = groupProjection.values().get(0);
    assertThat(aggregation.toStep(), is(Aggregation.Step.PARTIAL));
    Symbol aggregationInput = aggregation.inputs().get(0);
    assertThat(aggregationInput.symbolType(), is(SymbolType.INPUT_COLUMN));
    // reducer
    MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
    assertThat(mergePhase.projections().size(), is(2));
    Projection groupProjection1 = mergePhase.projections().get(0);
    assertThat(groupProjection1, instanceOf(GroupProjection.class));
    groupProjection = (GroupProjection) groupProjection1;
    assertThat(groupProjection.keys().get(0), instanceOf(InputColumn.class));
    assertThat(((InputColumn) groupProjection.keys().get(0)).index(), is(0));
    assertThat(groupProjection.values().get(0), instanceOf(Aggregation.class));
    Aggregation aggregationStep2 = groupProjection.values().get(0);
    assertThat(aggregationStep2.toStep(), is(Aggregation.Step.FINAL));
    OrderedTopNProjection topNProjection = (OrderedTopNProjection) mergePhase.projections().get(1);
    Symbol collection_count = topNProjection.outputs().get(0);
    assertThat(collection_count, instanceOf(Function.class));
    // handler
    MergePhase localMergeNode = distributedGroupByMerge.mergePhase();
    assertThat(localMergeNode.projections(), empty());
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) SymbolMatchers.isAggregation(io.crate.testing.SymbolMatchers.isAggregation) MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) DistributedGroupBy(io.crate.planner.node.dql.DistributedGroupBy) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 35 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNoDistributedGroupByOnAllPrimaryKeys.

@Test
public void testNoDistributedGroupByOnAllPrimaryKeys() throws Exception {
    Merge merge = e.plan("select count(*), id, date from empty_parted group by id, date limit 20");
    Collect collect = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    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(TopNProjection.class));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections().size(), is(1));
    assertThat(mergePhase.projections().get(0), instanceOf(TopNProjection.class));
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)48 Test (org.junit.Test)36 CrateUnitTest (io.crate.test.integration.CrateUnitTest)25 Collect (io.crate.planner.node.dql.Collect)18 MergePhase (io.crate.planner.node.dql.MergePhase)15 Merge (io.crate.planner.Merge)14 Routing (io.crate.metadata.Routing)10 Symbol (io.crate.analyze.symbol.Symbol)8 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)8 DistributedGroupBy (io.crate.planner.node.dql.DistributedGroupBy)7 Bucket (io.crate.data.Bucket)6 Reference (io.crate.metadata.Reference)6 Row (io.crate.data.Row)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 OrderBy (io.crate.analyze.OrderBy)3 Function (io.crate.analyze.symbol.Function)3 CollectionBucket (io.crate.data.CollectionBucket)3