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