Search in sources :

Example 6 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class CountPhaseTest method testStreaming.

@Test
public void testStreaming() throws Exception {
    Routing routing = new Routing(TreeMapBuilder.<String, Map<String, List<Integer>>>newMapBuilder().put("n1", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Arrays.asList(1, 2)).put("i2", Arrays.asList(1, 2)).map()).put("n2", TreeMapBuilder.<String, List<Integer>>newMapBuilder().put("i1", Collections.singletonList(3)).map()).map());
    CountPhase countPhase = new CountPhase(1, routing, WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    BytesStreamOutput out = new BytesStreamOutput(10);
    countPhase.writeTo(out);
    StreamInput in = StreamInput.wrap(out.bytes());
    CountPhase streamedNode = CountPhase.FACTORY.create();
    streamedNode.readFrom(in);
    assertThat(streamedNode.phaseId(), is(1));
    assertThat(streamedNode.nodeIds(), containsInAnyOrder("n1", "n2"));
    assertThat(streamedNode.routing(), equalTo(routing));
    assertThat(streamedNode.distributionInfo(), equalTo(DistributionInfo.DEFAULT_BROADCAST));
}
Also used : StreamInput(org.elasticsearch.common.io.stream.StreamInput) Routing(io.crate.metadata.Routing) Map(java.util.Map) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 7 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class DeleteStatementPlanner method collectWithDeleteProjection.

private static Plan collectWithDeleteProjection(TableInfo tableInfo, WhereClause whereClause, Planner.Context plannerContext) {
    // for delete, we always need to collect the `_uid`
    Reference idReference = tableInfo.getReference(DocSysColumns.ID);
    DeleteProjection deleteProjection = new DeleteProjection(new InputColumn(0, DataTypes.STRING));
    Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(plannerContext.jobId(), plannerContext.nextExecutionPhaseId(), "collect", routing, tableInfo.rowGranularity(), ImmutableList.of(idReference), ImmutableList.of(deleteProjection), 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) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) DeleteProjection(io.crate.planner.projection.DeleteProjection) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase)

Example 8 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class UpdateConsumer method createSysTableUpdatePlan.

private static Plan createSysTableUpdatePlan(TableInfo tableInfo, Planner.Context plannerContext, UpdateAnalyzedStatement.NestedAnalyzedStatement nestedStatement) {
    Routing routing = plannerContext.allocateRouting(tableInfo, nestedStatement.whereClause(), Preference.PRIMARY.type());
    Reference idReference = tableInfo.getReference(DocSysColumns.ID);
    assert idReference != null : "table has no _id column";
    SysUpdateProjection updateProjection = new SysUpdateProjection(idReference.valueType(), nestedStatement.assignments());
    return createPlan(plannerContext, routing, tableInfo, idReference, updateProjection, nestedStatement.whereClause());
}
Also used : SysUpdateProjection(io.crate.planner.projection.SysUpdateProjection) Reference(io.crate.metadata.Reference) Routing(io.crate.metadata.Routing)

Example 9 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class UpdateConsumer method upsertByQuery.

private static Plan upsertByQuery(UpdateAnalyzedStatement.NestedAnalyzedStatement nestedAnalysis, Planner.Context plannerContext, DocTableInfo tableInfo, WhereClause whereClause) {
    Symbol versionSymbol = null;
    if (whereClause.hasVersions()) {
        versionSymbol = VersionRewriter.get(whereClause.query());
        whereClause = new WhereClause(whereClause.query(), whereClause.docKeys().orElse(null), whereClause.partitions());
    }
    if (!whereClause.noMatch() || !(tableInfo.isPartitioned() && whereClause.partitions().isEmpty())) {
        // for updates, we always need to collect the `_id`
        Reference idReference = tableInfo.getReference(DocSysColumns.ID);
        Tuple<String[], Symbol[]> assignments = Assignments.convert(nestedAnalysis.assignments());
        Long version = null;
        if (versionSymbol != null) {
            version = ValueSymbolVisitor.LONG.process(versionSymbol);
        }
        UpdateProjection updateProjection = new UpdateProjection(new InputColumn(0, DataTypes.STRING), assignments.v1(), assignments.v2(), version);
        Routing routing = plannerContext.allocateRouting(tableInfo, whereClause, Preference.PRIMARY.type());
        return createPlan(plannerContext, routing, tableInfo, idReference, updateProjection, whereClause);
    } else {
        return null;
    }
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) Reference(io.crate.metadata.Reference) InputColumn(io.crate.analyze.symbol.InputColumn) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) SysUpdateProjection(io.crate.planner.projection.SysUpdateProjection) UpdateProjection(io.crate.planner.projection.UpdateProjection)

Example 10 with Routing

use of io.crate.metadata.Routing in project crate by crate.

the class RemoteCollectorTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    UUID jobId = UUID.randomUUID();
    RoutedCollectPhase collectPhase = new RoutedCollectPhase(jobId, 0, "remoteCollect", new Routing(ImmutableMap.<String, Map<String, List<Integer>>>of("remoteNode", ImmutableMap.of("dummyTable", Collections.singletonList(1)))), RowGranularity.DOC, Collections.<Symbol>singletonList(createReference("name", DataTypes.STRING)), Collections.<Projection>emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_BROADCAST);
    transportJobAction = mock(TransportJobAction.class);
    transportKillJobsNodeAction = mock(TransportKillJobsNodeAction.class);
    consumer = new TestingBatchConsumer();
    JobsLogs jobsLogs = new JobsLogs(() -> true);
    JobContextService jobContextService = new JobContextService(Settings.EMPTY, new NoopClusterService(), jobsLogs);
    remoteCollector = new RemoteCollector(jobId, "localNode", "remoteNode", transportJobAction, transportKillJobsNodeAction, jobContextService, mock(RamAccountingContext.class), consumer, collectPhase);
}
Also used : TransportJobAction(io.crate.action.job.TransportJobAction) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) Routing(io.crate.metadata.Routing) TestingBatchConsumer(io.crate.testing.TestingBatchConsumer) JobsLogs(io.crate.operation.collect.stats.JobsLogs) UUID(java.util.UUID) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) JobContextService(io.crate.jobs.JobContextService) Before(org.junit.Before)

Aggregations

Routing (io.crate.metadata.Routing)17 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)10 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 ImmutableList (com.google.common.collect.ImmutableList)4 Reference (io.crate.metadata.Reference)4 TableIdent (io.crate.metadata.TableIdent)4 Map (java.util.Map)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Symbol (io.crate.analyze.symbol.Symbol)3 TestingBatchConsumer (io.crate.testing.TestingBatchConsumer)3 List (java.util.List)3 SharedShardContexts (io.crate.action.job.SharedShardContexts)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 PartitionName (io.crate.metadata.PartitionName)2 NodeOperation (io.crate.operation.NodeOperation)2 JobsLogs (io.crate.operation.collect.stats.JobsLogs)2 MergePhase (io.crate.planner.node.dql.MergePhase)2 SysUpdateProjection (io.crate.planner.projection.SysUpdateProjection)2 Before (org.junit.Before)2