Search in sources :

Example 16 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class RingsAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String sourceV, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_depth") int depth, @QueryParam("source_in_ring") @DefaultValue("true") boolean sourceInRing, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity, @QueryParam("limit") @DefaultValue(DEFAULT_PATHS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get rings paths reachable from '{}' with " + "direction '{}', edge label '{}', max depth '{}', " + "source in ring '{}', max degree '{}', capacity '{}' " + "and limit '{}'", graph, sourceV, direction, edgeLabel, depth, sourceInRing, maxDegree, capacity, limit);
    Id source = VertexAPI.checkAndParseVertexId(sourceV);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    SubGraphTraverser traverser = new SubGraphTraverser(g);
    HugeTraverser.PathSet paths = traverser.rings(source, dir, edgeLabel, depth, sourceInRing, maxDegree, capacity, limit);
    return manager.serializer(g).writePaths("rings", paths, false);
}
Also used : SubGraphTraverser(com.baidu.hugegraph.traversal.algorithm.SubGraphTraverser) HugeGraph(com.baidu.hugegraph.HugeGraph) Directions(com.baidu.hugegraph.type.define.Directions) HugeTraverser(com.baidu.hugegraph.traversal.algorithm.HugeTraverser) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 17 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class KoutAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("source") String source, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_depth") int depth, @QueryParam("nearest") @DefaultValue("true") boolean nearest, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("capacity") @DefaultValue(DEFAULT_CAPACITY) long capacity, @QueryParam("limit") @DefaultValue(DEFAULT_ELEMENTS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get k-out from '{}' with " + "direction '{}', edge label '{}', max depth '{}', nearest " + "'{}', max degree '{}', capacity '{}' and limit '{}'", graph, source, direction, edgeLabel, depth, nearest, maxDegree, capacity, limit);
    Id sourceId = VertexAPI.checkAndParseVertexId(source);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    Set<Id> ids;
    try (KoutTraverser traverser = new KoutTraverser(g)) {
        ids = traverser.kout(sourceId, dir, edgeLabel, depth, nearest, maxDegree, capacity, limit);
    }
    return manager.serializer(g).writeList("vertices", ids);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) KoutTraverser(com.baidu.hugegraph.traversal.algorithm.KoutTraverser) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 18 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class SameNeighborsAPI method get.

@GET
@Timed
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String get(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("vertex") String vertex, @QueryParam("other") String other, @QueryParam("direction") String direction, @QueryParam("label") String edgeLabel, @QueryParam("max_degree") @DefaultValue(DEFAULT_MAX_DEGREE) long maxDegree, @QueryParam("limit") @DefaultValue(DEFAULT_ELEMENTS_LIMIT) long limit) {
    LOG.debug("Graph [{}] get same neighbors between '{}' and '{}' with " + "direction {}, edge label {}, max degree '{}' and limit '{}'", graph, vertex, other, direction, edgeLabel, maxDegree, limit);
    Id sourceId = VertexAPI.checkAndParseVertexId(vertex);
    Id targetId = VertexAPI.checkAndParseVertexId(other);
    Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
    HugeGraph g = graph(manager, graph);
    SameNeighborTraverser traverser = new SameNeighborTraverser(g);
    Set<Id> neighbors = traverser.sameNeighbors(sourceId, targetId, dir, edgeLabel, maxDegree, limit);
    return manager.serializer(g).writeList("same_neighbors", neighbors);
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SameNeighborTraverser(com.baidu.hugegraph.traversal.algorithm.SameNeighborTraverser) Directions(com.baidu.hugegraph.type.define.Directions) Id(com.baidu.hugegraph.backend.id.Id) Produces(jakarta.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(jakarta.ws.rs.GET)

Example 19 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class TextSerializer method writeQueryEdgeRangeCondition.

private Query writeQueryEdgeRangeCondition(ConditionQuery cq) {
    List<Condition> sortValues = cq.syspropConditions(HugeKeys.SORT_VALUES);
    E.checkArgument(sortValues.size() >= 1 && sortValues.size() <= 2, "Edge range query must be with sort-values range");
    // Would ignore target vertex
    Object vertex = cq.condition(HugeKeys.OWNER_VERTEX);
    Object direction = cq.condition(HugeKeys.DIRECTION);
    if (direction == null) {
        direction = Directions.OUT;
    }
    Object label = cq.condition(HugeKeys.LABEL);
    List<String> start = new ArrayList<>(cq.conditionsSize());
    start.add(writeEntryId((Id) vertex));
    start.add(writeType(((Directions) direction).type()));
    start.add(writeId((Id) label));
    List<String> end = new ArrayList<>(start);
    RangeConditions range = new RangeConditions(sortValues);
    if (range.keyMin() != null) {
        start.add((String) range.keyMin());
    }
    if (range.keyMax() != null) {
        end.add((String) range.keyMax());
    }
    // Sort-value will be empty if there is no start sort-value
    String startId = EdgeId.concat(start.toArray(new String[0]));
    // Set endId as prefix if there is no end sort-value
    String endId = EdgeId.concat(end.toArray(new String[0]));
    if (range.keyMax() == null) {
        return new IdPrefixQuery(cq, IdGenerator.of(startId), range.keyMinEq(), IdGenerator.of(endId));
    }
    return new IdRangeQuery(cq, IdGenerator.of(startId), range.keyMinEq(), IdGenerator.of(endId), range.keyMaxEq());
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Directions(com.baidu.hugegraph.type.define.Directions) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) RangeConditions(com.baidu.hugegraph.backend.query.Condition.RangeConditions) IdRangeQuery(com.baidu.hugegraph.backend.query.IdRangeQuery) IdPrefixQuery(com.baidu.hugegraph.backend.query.IdPrefixQuery)

Example 20 with Directions

use of com.baidu.hugegraph.type.define.Directions in project incubator-hugegraph by apache.

the class BinarySerializer method writeQueryEdgeRangeCondition.

private Query writeQueryEdgeRangeCondition(ConditionQuery cq) {
    List<Condition> sortValues = cq.syspropConditions(HugeKeys.SORT_VALUES);
    E.checkArgument(sortValues.size() >= 1 && sortValues.size() <= 2, "Edge range query must be with sort-values range");
    // Would ignore target vertex
    Id vertex = cq.condition(HugeKeys.OWNER_VERTEX);
    Directions direction = cq.condition(HugeKeys.DIRECTION);
    if (direction == null) {
        direction = Directions.OUT;
    }
    Id label = cq.condition(HugeKeys.LABEL);
    BytesBuffer start = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    writePartitionedId(HugeType.EDGE, vertex, start);
    start.write(direction.type().code());
    start.writeId(label);
    BytesBuffer end = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
    end.copyFrom(start);
    RangeConditions range = new RangeConditions(sortValues);
    if (range.keyMin() != null) {
        start.writeStringRaw((String) range.keyMin());
    }
    if (range.keyMax() != null) {
        end.writeStringRaw((String) range.keyMax());
    }
    // Sort-value will be empty if there is no start sort-value
    Id startId = new BinaryId(start.bytes(), null);
    // Set endId as prefix if there is no end sort-value
    Id endId = new BinaryId(end.bytes(), null);
    boolean includeStart = range.keyMinEq();
    if (cq.paging() && !cq.page().isEmpty()) {
        includeStart = true;
        byte[] position = PageState.fromString(cq.page()).position();
        E.checkArgument(Bytes.compare(position, startId.asBytes()) >= 0, "Invalid page out of lower bound");
        startId = new BinaryId(position, null);
    }
    if (range.keyMax() == null) {
        return new IdPrefixQuery(cq, startId, includeStart, endId);
    }
    return new IdRangeQuery(cq, startId, includeStart, endId, range.keyMaxEq());
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Directions(com.baidu.hugegraph.type.define.Directions) BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) RangeConditions(com.baidu.hugegraph.backend.query.Condition.RangeConditions) IdRangeQuery(com.baidu.hugegraph.backend.query.IdRangeQuery) IdPrefixQuery(com.baidu.hugegraph.backend.query.IdPrefixQuery)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)24 Directions (com.baidu.hugegraph.type.define.Directions)24 HugeGraph (com.baidu.hugegraph.HugeGraph)15 Timed (com.codahale.metrics.annotation.Timed)14 GET (jakarta.ws.rs.GET)14 Produces (jakarta.ws.rs.Produces)14 HugeTraverser (com.baidu.hugegraph.traversal.algorithm.HugeTraverser)6 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)3 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 RangeConditions (com.baidu.hugegraph.backend.query.Condition.RangeConditions)2 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)2 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)2 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)2 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)2 PathsTraverser (com.baidu.hugegraph.traversal.algorithm.PathsTraverser)2 PredictionTraverser (com.baidu.hugegraph.traversal.algorithm.PredictionTraverser)2 ShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.ShortestPathTraverser)2 SingleSourceShortestPathTraverser (com.baidu.hugegraph.traversal.algorithm.SingleSourceShortestPathTraverser)2