Search in sources :

Example 21 with RoutedCollectPhase

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

the class InsertPlannerTest method testInsertFromSubQueryReduceOnCollectorGroupByWithCast.

@Test
public void testInsertFromSubQueryReduceOnCollectorGroupByWithCast() {
    Merge merge = e.plan("insert into users (id, name) (select id, count(*) from users group by id)");
    Collect nonDistributedGroupBy = (Collect) merge.subPlan();
    RoutedCollectPhase collectPhase = ((RoutedCollectPhase) nonDistributedGroupBy.collectPhase());
    assertThat(collectPhase.projections(), contains(instanceOf(GroupProjection.class), instanceOf(EvalProjection.class), instanceOf(ColumnIndexWriterProjection.class)));
    EvalProjection collectTopN = (EvalProjection) collectPhase.projections().get(1);
    assertThat(collectTopN.outputs(), contains(isInputColumn(0), isFunction(ImplicitCastFunction.NAME, List.of(DataTypes.LONG, DataTypes.STRING))));
    ColumnIndexWriterProjection columnIndexWriterProjection = (ColumnIndexWriterProjection) collectPhase.projections().get(2);
    assertThat(columnIndexWriterProjection.columnReferencesExclPartition(), contains(isReference("id"), isReference("name")));
    MergePhase mergePhase = merge.mergePhase();
    assertThat(mergePhase.projections(), contains(instanceOf(MergeCountProjection.class)));
}
Also used : MergePhase(io.crate.execution.dsl.phases.MergePhase) Collect(io.crate.planner.node.dql.Collect) EvalProjection(io.crate.execution.dsl.projection.EvalProjection) ColumnIndexWriterProjection(io.crate.execution.dsl.projection.ColumnIndexWriterProjection) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 22 with RoutedCollectPhase

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

the class RoutedCollectPhaseTest method testNormalizeNoop.

@Test
public void testNormalizeNoop() throws Exception {
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(Literal.of(10)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect, sameInstance(collect));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 23 with RoutedCollectPhase

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

the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.

@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.orderBy(new OrderBy(Collections.singletonList(toInt10)));
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.orderBy(), notNullValue());
}
Also used : OrderBy(io.crate.analyze.OrderBy) CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 24 with RoutedCollectPhase

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

the class RoutedCollectPhaseTest method testNormalizePreservesNodePageSizeHint.

@Test
public void testNormalizePreservesNodePageSizeHint() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_SAME_NODE);
    collect.nodePageSizeHint(10);
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(nodeCtx);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new CoordinatorTxnCtx(SessionContext.systemSessionContext()));
    assertThat(normalizedCollect.nodePageSizeHint(), is(10));
}
Also used : CoordinatorTxnCtx(io.crate.metadata.CoordinatorTxnCtx) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 25 with RoutedCollectPhase

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

the class RemoteCollectorTest method prepare.

@Before
public void prepare() {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(Map.of("remoteNode", Map.of("dummyTable", IntArrayList.from(1)))), RowGranularity.DOC, Collections.singletonList(createReference("name", DataTypes.STRING)), Collections.emptyList(), WhereClause.MATCH_ALL.queryOrFallback(), DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    TasksService tasksService = new TasksService(clusterService, new JobsLogs(() -> true));
    numBroadcastCalls = new AtomicInteger(0);
    transportKillJobsNodeAction = new TransportKillJobsNodeAction(tasksService, clusterService, mock(TransportService.class)) {

        @Override
        public void broadcast(KillJobsRequest request, ActionListener<Long> listener) {
            numBroadcastCalls.incrementAndGet();
        }
    };
    consumer = new TestingRowConsumer();
    remoteCollector = new RemoteCollector(jobId, new SessionSettings("dummyUser", SearchPath.createSearchPathFrom("dummySchema")), "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, Runnable::run, tasksService, RamAccounting.NO_ACCOUNTING, consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.execution.jobs.transport.TransportJobAction) TransportKillJobsNodeAction(io.crate.execution.jobs.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TasksService(io.crate.execution.jobs.TasksService) SessionSettings(io.crate.metadata.settings.SessionSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KillJobsRequest(io.crate.execution.jobs.kill.KillJobsRequest) JobsLogs(io.crate.execution.engine.collect.stats.JobsLogs) UUID(java.util.UUID) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) TestingRowConsumer(io.crate.testing.TestingRowConsumer) Before(org.junit.Before)

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