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