Search in sources :

Example 11 with RoutedCollectPhase

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

the class GroupByPlannerTest method testNonDistributedGroupByOnClusteredColumn.

@Test
public void testNonDistributedGroupByOnClusteredColumn() throws Exception {
    Merge merge = e.plan("select count(*), id from users group by id limit 20");
    Collect collect = ((Collect) merge.subPlan());
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.projections().size(), is(2));
    assertThat(collectPhase.projections().get(1), instanceOf(TopNProjection.class));
    assertThat(collectPhase.projections().get(0).requiredGranularity(), is(RowGranularity.SHARD));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections().size(), is(1));
}
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)

Example 12 with RoutedCollectPhase

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

the class GroupByPlannerTest method testHandlerSideRoutingGroupBy.

@Test
public void testHandlerSideRoutingGroupBy() throws Exception {
    Merge merge = e.plan("select count(*) from sys.cluster group by name");
    Collect collect = (Collect) merge.subPlan();
    // just testing the dispatching here.. making sure it is not a ESSearchNode
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) collect.collectPhase());
    assertThat(collectPhase.toCollect().get(0), instanceOf(Reference.class));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class)));
    assertThat(merge.mergePhase().projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class)));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with RoutedCollectPhase

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

the class GroupByPlannerTest method testGroupByWithAggregationPlan.

@Test
public void testGroupByWithAggregationPlan() throws Exception {
    Merge distributedGroupByMerge = e.plan("select count(*), name from users group by name");
    DistributedGroupBy distributedGroupBy = (DistributedGroupBy) distributedGroupByMerge.subPlan();
    // distributed collect
    RoutedCollectPhase collectPhase = distributedGroupBy.collectPhase();
    assertThat(collectPhase.maxRowGranularity(), is(RowGranularity.DOC));
    assertThat(collectPhase.nodeIds().size(), is(2));
    assertThat(collectPhase.toCollect().size(), is(1));
    assertThat(collectPhase.projections().size(), is(1));
    assertThat(collectPhase.projections().get(0), instanceOf(GroupProjection.class));
    assertThat(collectPhase.outputTypes().size(), is(2));
    assertEquals(DataTypes.STRING, collectPhase.outputTypes().get(0));
    assertEquals(CountAggregation.LongStateType.INSTANCE, collectPhase.outputTypes().get(1));
    MergePhase mergePhase = distributedGroupBy.reducerMergeNode();
    assertThat(mergePhase.numUpstreams(), is(2));
    assertThat(mergePhase.nodeIds().size(), is(2));
    assertEquals(mergePhase.inputTypes(), collectPhase.outputTypes());
    // for function evaluation and column-reordering there is always a EvalProjection
    assertThat(mergePhase.projections().size(), is(2));
    assertThat(mergePhase.projections().get(1), instanceOf(EvalProjection.class));
    assertThat(mergePhase.projections().get(0), instanceOf(GroupProjection.class));
    GroupProjection groupProjection = (GroupProjection) mergePhase.projections().get(0);
    InputColumn inputColumn = (InputColumn) groupProjection.values().get(0).inputs().get(0);
    assertThat(inputColumn.index(), is(1));
    assertThat(mergePhase.outputTypes().size(), is(2));
    assertEquals(DataTypes.LONG, mergePhase.outputTypes().get(0));
    assertEquals(DataTypes.STRING, mergePhase.outputTypes().get(1));
    MergePhase localMerge = distributedGroupByMerge.mergePhase();
    assertThat(localMerge.numUpstreams(), is(2));
    assertThat(localMerge.nodeIds().size(), is(1));
    assertThat(Iterables.getOnlyElement(localMerge.nodeIds()), is("noop_id"));
    assertEquals(mergePhase.outputTypes(), localMerge.inputTypes());
    assertThat(localMerge.projections(), empty());
}
Also used : MergePhase(io.crate.planner.node.dql.MergePhase) Merge(io.crate.planner.Merge) 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 14 with RoutedCollectPhase

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

the class NodeStatsCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase phase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    RoutedCollectPhase collectPhase = (RoutedCollectPhase) phase;
    if (collectPhase.whereClause().noMatch()) {
        return RowsCollector.empty(consumer);
    }
    Collection<DiscoveryNode> nodes = nodeIds(collectPhase.whereClause(), Lists.newArrayList(clusterService.state().getNodes().iterator()), functions);
    if (nodes.isEmpty()) {
        return RowsCollector.empty(consumer);
    }
    BatchIterator nodeStatsIterator = NodeStatsIterator.newInstance(nodeStatsAction, collectPhase, nodes, inputFactory);
    return BatchIteratorCollectorBridge.newInstance(nodeStatsIterator, consumer);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) BatchIterator(io.crate.data.BatchIterator) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 15 with RoutedCollectPhase

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

the class LuceneShardCollectorProvider method getOrderedCollector.

@Override
public OrderedDocCollector getOrderedCollector(RoutedCollectPhase phase, SharedShardContext sharedShardContext, JobCollectContext jobCollectContext, boolean requiresRepeat) {
    RoutedCollectPhase collectPhase = phase.normalize(shardNormalizer, null);
    CollectorContext collectorContext;
    InputFactory.Context<? extends LuceneCollectorExpression<?>> ctx;
    Engine.Searcher searcher = null;
    LuceneQueryBuilder.Context queryContext;
    try {
        searcher = sharedShardContext.acquireSearcher();
        IndexService indexService = sharedShardContext.indexService();
        queryContext = luceneQueryBuilder.convert(collectPhase.whereClause(), indexService.mapperService(), indexService.fieldData(), indexService.cache());
        jobCollectContext.addSearcher(sharedShardContext.readerId(), searcher);
        ctx = docInputFactory.extractImplementations(collectPhase);
        collectorContext = getCollectorContext(sharedShardContext.readerId(), ctx);
    } catch (Throwable t) {
        if (searcher != null) {
            searcher.close();
        }
        throw t;
    }
    int batchSize = collectPhase.shardQueueSize(localNodeId);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("[{}][{}] creating LuceneOrderedDocCollector. Expected number of rows to be collected: {}", sharedShardContext.indexShard().routingEntry().currentNodeId(), sharedShardContext.indexShard().shardId(), batchSize);
    }
    return new LuceneOrderedDocCollector(indexShard.shardId(), searcher.searcher(), queryContext.query(), queryContext.minScore(), Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.SCORE), batchSize, fieldTypeLookup, collectorContext, collectPhase.orderBy(), LuceneSortGenerator.generateLuceneSort(collectorContext, collectPhase.orderBy(), docInputFactory, fieldTypeLookup), ctx.topLevelInputs(), ctx.expressions());
}
Also used : InputFactory(io.crate.operation.InputFactory) IndexService(org.elasticsearch.index.IndexService) LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) LuceneOrderedDocCollector(io.crate.operation.collect.collectors.LuceneOrderedDocCollector) Engine(org.elasticsearch.index.engine.Engine) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

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