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));
}
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)));
}
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());
}
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);
}
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());
}
Aggregations