Search in sources :

Example 41 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class ShardCollectorProvider method getIterator.

private BatchIterator<Row> getIterator(RoutedCollectPhase collectPhase, boolean requiresScroll, CollectTask collectTask) throws Exception {
    assert collectPhase.orderBy() == null : "getDocCollector shouldn't be called if there is an orderBy on the collectPhase";
    assert collectPhase.maxRowGranularity() == RowGranularity.DOC : "granularity must be DOC";
    boolean isOpenIndex = indexShard.mapperService() != null;
    RoutedCollectPhase normalizedCollectNode = collectPhase.normalize(shardNormalizer, collectTask.txnCtx());
    if (isOpenIndex) {
        BatchIterator<Row> fusedIterator = getProjectionFusedIterator(normalizedCollectNode, collectTask);
        if (fusedIterator != null) {
            return fusedIterator;
        }
    }
    final BatchIterator<Row> iterator;
    if (isOpenIndex && WhereClause.canMatch(normalizedCollectNode.where())) {
        iterator = getUnorderedIterator(normalizedCollectNode, requiresScroll, collectTask);
    } else {
        iterator = InMemoryBatchIterator.empty(SentinelRow.SENTINEL);
    }
    return Projectors.wrap(Projections.shardProjections(collectPhase.projections()), collectPhase.jobId(), collectTask.txnCtx(), collectTask.getRamAccounting(), collectTask.memoryManager(), projectorFactory, iterator);
}
Also used : Row(io.crate.data.Row) SentinelRow(io.crate.data.SentinelRow) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 42 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class DistributingConsumerFactoryTest method createDownstream.

private RowConsumer createDownstream(Set<String> downstreamExecutionNodes) {
    UUID jobId = UUID.randomUUID();
    Routing routing = new Routing(Map.of("n1", Map.of("i1", IntArrayList.from(1, 2))));
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 1, "collect", routing, RowGranularity.DOC, List.of(), List.of(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_MODULO);
    MergePhase mergePhase = new MergePhase(jobId, 2, "merge", 1, 1, downstreamExecutionNodes, List.of(LongType.INSTANCE), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
    NodeOperation nodeOperation = NodeOperation.withDownstream(collectPhase, mergePhase, (byte) 0);
    return rowDownstreamFactory.create(nodeOperation, RamAccounting.NO_ACCOUNTING, collectPhase.distributionInfo(), jobId, Paging.PAGE_SIZE);
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Routing(io.crate.metadata.Routing) NodeOperation(io.crate.execution.dsl.phases.NodeOperation) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 43 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class CollectQueryCastRulesTest method assertCollectQuery.

private void assertCollectQuery(String query, String expected) {
    var collect = new Collect(tr1, Collections.emptyList(), new WhereClause(e.asSymbol(query)), 100, 10);
    var plan = (io.crate.planner.node.dql.Collect) collect.build(plannerContext, Set.of(), new ProjectionBuilder(e.nodeCtx), TopN.NO_LIMIT, 0, null, null, Row.EMPTY, new SubQueryResults(emptyMap()) {

        @Override
        public Object getSafe(SelectSymbol key) {
            return Literal.of(key.valueType(), null);
        }
    });
    assertThat(((RoutedCollectPhase) plan.collectPhase()).where().toString(), is(expected));
}
Also used : SelectSymbol(io.crate.expression.symbol.SelectSymbol) Collect(io.crate.planner.operators.Collect) SubQueryResults(io.crate.planner.operators.SubQueryResults) WhereClause(io.crate.analyze.WhereClause) ProjectionBuilder(io.crate.execution.dsl.projection.builder.ProjectionBuilder) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase)

Example 44 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class CopyToPlannerTest method testCopyToWithPartitionInWhereClauseRoutesToPartitionIndexOnly.

@Test
public void testCopyToWithPartitionInWhereClauseRoutesToPartitionIndexOnly() {
    Merge merge = plan("copy parted where date = 1395874800000 to directory '/tmp/foo'");
    Collect collect = (Collect) merge.subPlan();
    String expectedIndex = new PartitionName(new RelationName("doc", "parted"), singletonList("1395874800000")).asIndexName();
    assertThat(((RoutedCollectPhase) collect.collectPhase()).routing().locations().values().stream().flatMap(shardsByIndices -> shardsByIndices.keySet().stream()).collect(Collectors.toSet()), contains(expectedIndex));
}
Also used : PartitionName(io.crate.metadata.PartitionName) Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) RelationName(io.crate.metadata.RelationName) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Example 45 with RoutedCollectPhase

use of io.crate.execution.dsl.phases.RoutedCollectPhase in project crate by crate.

the class CopyToPlannerTest method testCopyToWithColumnsReferenceRewrite.

@Test
public void testCopyToWithColumnsReferenceRewrite() {
    Merge plan = 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.column().name(), is(DocSysColumns.DOC.name()));
    assertThat(nameRef.column().path().get(0), is("name"));
}
Also used : Merge(io.crate.planner.Merge) Collect(io.crate.planner.node.dql.Collect) Reference(io.crate.metadata.Reference) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test) RandomizedTest(com.carrotsearch.randomizedtesting.RandomizedTest)

Aggregations

RoutedCollectPhase (io.crate.execution.dsl.phases.RoutedCollectPhase)50 Test (org.junit.Test)39 Collect (io.crate.planner.node.dql.Collect)23 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)23 RandomizedTest (com.carrotsearch.randomizedtesting.RandomizedTest)18 Routing (io.crate.metadata.Routing)18 MergePhase (io.crate.execution.dsl.phases.MergePhase)14 Merge (io.crate.planner.Merge)10 Symbol (io.crate.expression.symbol.Symbol)9 GroupProjection (io.crate.execution.dsl.projection.GroupProjection)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 EvalProjection (io.crate.execution.dsl.projection.EvalProjection)7 ArrayList (java.util.ArrayList)6 Bucket (io.crate.data.Bucket)5 RelationName (io.crate.metadata.RelationName)5 UUID (java.util.UUID)4 ClusterService (org.elasticsearch.cluster.service.ClusterService)4 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)3 OrderBy (io.crate.analyze.OrderBy)3