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; }
@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); return idColumnValue(edgeId); }
public EdgeId directed(boolean directed) { return new EdgeId(this.ownerVertexId, this.direction, this.edgeLabelId, this.sortValues, this.otherVertexId, directed); }
String table = this.edgesTable(id.direction()); Delete delete = QueryBuilder.delete().from(table); for (int i = 0, n = idNames.size(); i < n; i++) { EdgeId id = EdgeId.parse(rawId.asString()).directed(true); assert id.direction() == Directions.OUT; deleteEdge.accept(id); deleteEdge.accept(id.switchDirection());
public static Id getIdValue(Object idValue) { Id id = HugeElement.getIdValue(idValue); if (id == null || id instanceof EdgeId) { return id; } return EdgeId.parse(id.asString()); } }
private Set<Id> adjacentVertices(Set<Id> vertices, Directions dir, Id label, Set<Id> excluded, long degree, long limit) { if (limit == 0) { return ImmutableSet.of(); } Set<Id> neighbors = newSet(); for (Id source : vertices) { Iterator<Edge> edges = this.edgesOfVertex(source, dir, label, degree); while (edges.hasNext()) { HugeEdge e = (HugeEdge) edges.next(); Id target = e.id().otherVertexId(); if (excluded != null && excluded.contains(target)) { continue; } neighbors.add(target); if (limit != NO_LIMIT && neighbors.size() >= limit) { return neighbors; } } } return neighbors; }
private BackendEntry getEntryById(Id id, Map<Id, BackendEntry> entries) { // TODO: improve id split Id entryId = IdGenerator.of(EdgeId.split(id)[0]); return entries.get(entryId); }
@Test public void testEdgeIdEqual() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh")); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko")); Assert.assertTrue(edgeId1.equals(edgeId2)); Assert.assertTrue(edgeId2.equals(edgeId1)); Assert.assertTrue(edgeId1.equals(edgeId3)); Assert.assertTrue(edgeId3.equals(edgeId1)); }
@Watched(prefix = "edge") public EdgeId idWithDirection() { return ((EdgeId) this.id).directed(true); }
String table = this.edgesTable(id.direction()); Delete delete = QueryBuilder.delete().from(table); for (int i = 0, n = idNames.size(); i < n; i++) { EdgeId id = EdgeId.parse(rawId.asString()).directed(true); assert id.direction() == Directions.OUT; deleteEdge.accept(id); deleteEdge.accept(id.switchDirection());
@Override public EdgeId read(Kryo kryo, Input input, Class<EdgeId> clazz) { int length = input.read(); byte[] idBytes = input.readBytes(length); return EdgeId.parse(StringEncoding.decode(idBytes)); } }
while (edges.hasNext()) { HugeEdge edge = (HugeEdge) edges.next(); Id target = edge.id().otherVertexId();
public static String[] split(Id id) { return EdgeId.split(id.asString()); }
@Test public void testEdgeIdEqualWithDirection() { EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT, IdGenerator.of(1), "", IdGenerator.of("1:josh"), true); EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN, IdGenerator.of(1), "", IdGenerator.of("1:marko"), true); Assert.assertTrue(edgeId1.equals(edgeId2)); Assert.assertTrue(edgeId2.equals(edgeId1)); Assert.assertFalse(edgeId1.equals(edgeId3)); Assert.assertFalse(edgeId3.equals(edgeId1)); }
@Watched(prefix = "edge") public EdgeId idWithDirection() { return ((EdgeId) this.id).directed(true); }
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); return idColumnValue(edgeId); }
@Override public T deserialize(JsonParser jsonParser, DeserializationContext ctxt) throws IOException { Class<?> clazz = this.handledType(); if (clazz.equals(IdGenerator.LongId.class)) { Number idValue = ctxt.readValue(jsonParser, Number.class); return (T) IdGenerator.of(idValue.longValue()); } else if (clazz.equals(IdGenerator.StringId.class)) { String idValue = ctxt.readValue(jsonParser, String.class); return (T) IdGenerator.of(idValue); } else { assert clazz.equals(EdgeId.class); String idValue = ctxt.readValue(jsonParser, String.class); return (T) EdgeId.parse(idValue); } } }