Search in sources :

Example 1 with CountTraverser

use of com.baidu.hugegraph.traversal.algorithm.CountTraverser in project incubator-hugegraph by apache.

the class CountAPI method post.

@POST
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String post(@Context GraphManager manager, @PathParam("graph") String graph, CountRequest request) {
    LOG.debug("Graph [{}] get count from '{}' with request {}", graph, request);
    E.checkArgumentNotNull(request.source, "The source of request can't be null");
    Id sourceId = HugeVertex.getIdValue(request.source);
    E.checkArgumentNotNull(request.steps != null && !request.steps.isEmpty(), "The steps of request can't be null or empty");
    E.checkArgumentNotNull(request.dedupSize == NO_LIMIT || request.dedupSize >= 0L, "The dedup size of request " + "must >= 0 or == -1, but got: '%s'", request.dedupSize);
    HugeGraph g = graph(manager, graph);
    List<EdgeStep> steps = steps(g, request);
    CountTraverser traverser = new CountTraverser(g);
    long count = traverser.count(sourceId, steps, request.containsTraversed, request.dedupSize);
    return manager.serializer(g).writeMap(ImmutableMap.of("count", count));
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeStep(com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep) Id(com.baidu.hugegraph.backend.id.Id) CountTraverser(com.baidu.hugegraph.traversal.algorithm.CountTraverser) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

HugeGraph (com.baidu.hugegraph.HugeGraph)1 Id (com.baidu.hugegraph.backend.id.Id)1 CountTraverser (com.baidu.hugegraph.traversal.algorithm.CountTraverser)1 EdgeStep (com.baidu.hugegraph.traversal.algorithm.steps.EdgeStep)1 Timed (com.codahale.metrics.annotation.Timed)1 POST (jakarta.ws.rs.POST)1 Produces (jakarta.ws.rs.Produces)1