use of ai.grakn.graql.internal.analytics.ConnectedComponentVertexProgram in project grakn by graknlabs.
the class TinkerComputeQueryRunner method run.
public <T> ComputeJob<T> run(ConnectedComponentQuery<T> query) {
return runCompute(query, tinkerComputeQuery -> {
if (!tinkerComputeQuery.selectedTypesHaveInstance()) {
LOG.info("Selected types don't have instances");
return (T) Collections.emptyMap();
}
Set<LabelId> subLabelIds = convertLabelsToIds(tinkerComputeQuery.subLabels());
GraknVertexProgram<?> vertexProgram;
if (query.sourceId().isPresent()) {
ConceptId conceptId = query.sourceId().get();
if (!tinkerComputeQuery.verticesExistInSubgraph(conceptId)) {
throw GraqlQueryException.instanceDoesNotExist();
}
vertexProgram = new ConnectedComponentVertexProgram(conceptId);
} else {
vertexProgram = new ConnectedComponentsVertexProgram();
}
Long clusterSize = query.clusterSize();
GraknMapReduce<?> mapReduce;
if (query.isMembersSet()) {
mapReduce = new ClusterMemberMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
} else {
mapReduce = new ClusterSizeMapReduce(ConnectedComponentsVertexProgram.CLUSTER_LABEL, clusterSize);
}
Memory memory = tinkerComputeQuery.compute(vertexProgram, mapReduce, subLabelIds).memory();
return memory.get(mapReduce.getClass().getName());
});
}
Aggregations