protected final List<Object> idColumnValue(EdgeId edgeId) { List<Object> list = new ArrayList<>(5); list.add(IdUtil.writeString(edgeId.ownerVertexId())); list.add(edgeId.direction().code()); list.add(edgeId.edgeLabelId().asLong()); list.add(edgeId.sortValues()); list.add(IdUtil.writeString(edgeId.otherVertexId())); return list; }
@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("max_degree") @DefaultValue("-1") long degree, @QueryParam("capacity") @DefaultValue("-1") long capacity, @QueryParam("limit") @DefaultValue("-1") long limit) { LOG.debug("Graph [{}] get rays paths from '{}' with " + "direction '{}', edge label '{}', max depth '{}', " + "max degree '{}' and limit '{}'", graph, sourceV, direction, edgeLabel, depth, degree, limit); Id source = VertexAPI.checkAndParseVertexId(sourceV); Directions dir = Directions.convert(EdgeAPI.parseDirection(direction)); HugeGraph g = graph(manager, graph); HugeTraverser traverser = new HugeTraverser(g); List<HugeTraverser.Path> paths = traverser.rays(source, dir, edgeLabel, depth, degree, capacity, limit); return manager.serializer(g).writePaths("rays", paths, false); } }
public EdgeId switchDirection() { Directions direction = this.direction.opposite(); return new EdgeId(this.otherVertexId, direction, this.edgeLabelId, this.sortValues, this.ownerVertexId, this.directed); }
private static String table(Directions direction) { assert direction == Directions.OUT || direction == Directions.IN; return TABLE_PREFIX + "_" + direction.string(); }
private Query writeQueryEdgePrefixCondition(ConditionQuery cq) { // Convert query-by-condition to query-by-id List<String> condParts = new ArrayList<>(cq.conditions().size()); for (HugeKeys key : EdgeId.KEYS) { Object value = cq.condition(key); if (value == null) { break; } // Serialize condition value if (key == HugeKeys.OWNER_VERTEX || key == HugeKeys.OTHER_VERTEX) { condParts.add(writeEntryId((Id) value)); } else if (key == HugeKeys.DIRECTION) { condParts.add(writeType(((Directions) value).type())); } else if (key == HugeKeys.LABEL) { condParts.add(writeId((Id) value)); } else { condParts.add(value.toString()); } } if (condParts.size() > 0) { // Conditions to id String id = EdgeId.concat(condParts.toArray(new String[0])); return new IdPrefixQuery(cq, IdGenerator.of(id)); } return null; }
Directions opposite = this.direction.opposite();
public static String table(Directions direction) { assert direction == Directions.OUT || direction == Directions.IN; return TABLE_PREFIX + "_" + direction.string(); }
private String writeEdgeId(Id id, boolean withOwnerVertex) { EdgeId edgeId; if (id instanceof EdgeId) { edgeId = (EdgeId) id; } else { edgeId = EdgeId.parse(id.asString()); } List<String> list = new ArrayList<>(5); if (withOwnerVertex) { list.add(writeEntryId(edgeId.ownerVertexId())); } // Edge name: type + edge-label-name + sortKeys + targetVertex list.add(writeType(edgeId.direction().type())); list.add(writeId(edgeId.edgeLabelId())); list.add(edgeId.sortValues()); list.add(writeEntryId(edgeId.otherVertexId())); return EdgeId.concat(list.toArray(new String[0])); }
@Override protected List<Object> idColumnValue(Id id) { EdgeId edgeId; if (!(id instanceof EdgeId)) { String[] idParts = EdgeId.split(id); if (idParts.length == 1) { // Delete edge by label return Arrays.asList((Object[]) idParts); } id = IdUtil.readString(id.asString()); edgeId = EdgeId.parse(id.asString()); } else { edgeId = (EdgeId) id; } E.checkState(edgeId.direction() == this.direction, "Can't query %s edges from %s edges table", edgeId.direction(), this.direction); List<Object> list = new ArrayList<>(5); list.add(IdUtil.writeString(edgeId.ownerVertexId())); list.add(edgeId.direction().code()); list.add(edgeId.edgeLabelId().asLong()); list.add(edgeId.sortValues()); list.add(IdUtil.writeString(edgeId.otherVertexId())); return list; }
@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("max_degree") @DefaultValue("-1") long degree, @QueryParam("capacity") @DefaultValue("-1") long capacity, @QueryParam("limit") @DefaultValue("-1") long limit) { LOG.debug("Graph [{}] get rings paths reachable from '{}' with " + "direction '{}', edge label '{}', max depth '{}', " + "max degree '{}' and limit '{}'", graph, sourceV, direction, edgeLabel, depth, degree, limit); Id source = VertexAPI.checkAndParseVertexId(sourceV); Directions dir = Directions.convert(EdgeAPI.parseDirection(direction)); HugeGraph g = graph(manager, graph); HugeTraverser traverser = new HugeTraverser(g); List<HugeTraverser.Path> paths = traverser.rings(source, dir, edgeLabel, depth, degree, capacity, limit); return manager.serializer(g).writePaths("rings", paths, false); } }
E.checkNotNull(targetDir, "target direction"); E.checkArgument(sourceDir == targetDir || sourceDir == targetDir.opposite(), "Source direction must equal to target direction," + "or opposite to target direction");
public static String table(Directions direction) { assert direction == Directions.OUT || direction == Directions.IN; return TABLE_PREFIX + "_" + direction.string(); }
start.add(writeType(((Directions) direction).type())); start.add(writeId((Id) label));
@Override protected List<Object> idColumnValue(Id id) { EdgeId edgeId; if (!(id instanceof EdgeId)) { String[] idParts = EdgeId.split(id); if (idParts.length == 1) { // Delete edge by label return Arrays.asList((Object[]) idParts); } id = IdUtil.readString(id.asString()); edgeId = EdgeId.parse(id.asString()); } else { edgeId = (EdgeId) id; } E.checkState(edgeId.direction() == this.direction, "Can't query %s edges from %s edges table", edgeId.direction(), this.direction); List<Object> list = new ArrayList<>(5); list.add(IdUtil.writeString(edgeId.ownerVertexId())); list.add(edgeId.direction().code()); list.add(edgeId.edgeLabelId().asLong()); list.add(edgeId.sortValues()); list.add(IdUtil.writeString(edgeId.otherVertexId())); return list; }
Directions dir = Directions.convert(EdgeAPI.parseDirection(direction));
public EdgeId switchDirection() { Directions direction = this.direction.opposite(); return new EdgeId(this.otherVertexId, direction, this.edgeLabelId, this.sortValues, this.ownerVertexId, this.directed); }
private static String table(Directions direction) { assert direction == Directions.OUT || direction == Directions.IN; return TABLE_PREFIX + "_" + direction.string(); }