@Nullable @Override public JanusGraphVertex apply(@Nullable JanusGraphEdge janusgraphEdge) { return janusgraphEdge.otherVertex(other); } });
@Override default JanusGraphVertex inVertex() { return vertex(Direction.IN); }
public boolean matchesConstraint(JanusGraphSchemaType type, JanusGraphElement element) { Preconditions.checkArgument(type != null && element!=null); assert isInstance(element); assert isValidConstraint(type); switch(this) { case VERTEX: return ((JanusGraphVertex)element).vertexLabel().equals(type); case EDGE: return ((JanusGraphEdge)element).edgeLabel().equals(type); case PROPERTY: return ((JanusGraphVertexProperty)element).propertyKey().equals(type); default: throw new IllegalArgumentException(); } }
public Connection(JanusGraphEdge connectionEdge) { this.outgoingVertexLabel = (VertexLabel) connectionEdge.outVertex(); this.incomingVertexLabel = (VertexLabel) connectionEdge.inVertex(); TypeDefinitionDescription value = connectionEdge.valueOrNull(BaseKey.SchemaDefinitionDesc); this.edgeLabel = (String) value.getModifier(); this.connectionEdge = connectionEdge; }
private void setStatusEdges(JanusGraphSchemaVertex vertex, SchemaStatus status, Set<PropertyKeyVertex> keys) { Preconditions.checkArgument(vertex.asIndexType().isMixedIndex()); for (JanusGraphEdge edge : vertex.getEdges(TypeDefinitionCategory.INDEX_FIELD, Direction.OUT)) { if (!keys.contains(edge.vertex(Direction.IN))) continue; //Only address edges with matching keys TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc); assert desc.getCategory() == TypeDefinitionCategory.INDEX_FIELD; Parameter[] parameters = (Parameter[]) desc.getModifier(); assert parameters[parameters.length - 1].key().equals(ParameterType.STATUS.getName()); if (parameters[parameters.length - 1].value().equals(status)) continue; Parameter[] paraCopy = Arrays.copyOf(parameters, parameters.length); paraCopy[parameters.length - 1] = ParameterType.STATUS.getParameter(status); edge.remove(); addSchemaEdge(vertex, edge.vertex(Direction.IN), TypeDefinitionCategory.INDEX_FIELD, paraCopy); } for (PropertyKeyVertex prop : keys) prop.resetCache(); }
JanusGraphEdge e1 = Iterables.getOnlyElement(changes.getEdges(v, Change.REMOVED, Direction.OUT, "knows")); assertFalse(e1.property("weight").isPresent()); assertEquals(v, e1.vertex(Direction.IN)); e1 = Iterables.getOnlyElement(changes.getEdges(v, Change.ADDED, Direction.OUT, "knows")); assertEquals(44.4, e1.<Float>value("weight").doubleValue(), 0.01); assertEquals(v, e1.vertex(Direction.IN));
assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges()); final JanusGraphEdge tmpE = Iterables.getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges()); assertEquals(5, tmpE.<Integer>value("time") % 10); final JanusGraphEdge ef = Iterables.getOnlyElement(v1.query().direction(Direction.OUT).labels("friend").edges()); assertEquals(ef, getOnlyElement(graph.query().has("type", 0).edges())); ef.property("type", 1); graph.tx().commit(); assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges()); assertEquals(5, getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges()) .<Integer>value("time") % 10); assertCount(1, v.query().direction(Direction.OUT).labels("knows").edges()); assertEquals(5, getOnlyElement(v.query().direction(Direction.OUT).labels("knows").edges()) .<Integer>value("time") % 10);
nodeEdgeIds[i] = new HashSet(10); for (Object r : nodeEdges[i]) { nodeEdgeIds[i].add(((JanusGraphEdge) r).longId()); for (Object o : n.query().direction(Direction.OUT).labels("knows").edges()) { JanusGraphEdge r = (JanusGraphEdge) o; JanusGraphVertex n2 = r.vertex(Direction.IN); int idSum = ((Number) n.value("uid")).intValue() + ((Number) n2.value("uid")).intValue(); assertEquals(idSum, ((Number) r.value("uid")).intValue()); double k = ((Number) r.value("weight")).doubleValue() / 1.5; int ki = (int) k; assertEquals(i + "-" + ki, r.value("name")); edgeIds.add(((JanusGraphEdge) r).longId());
private void updateConnectionEdgeConstraints(JanusGraphSchemaVertex edgeLabel, String oldName, String newName) { if (!(edgeLabel instanceof EdgeLabel)) return; ((EdgeLabel) edgeLabel).mappedConnections().stream() .peek(s -> schemaCache.expireSchemaElement(s.getOutgoingVertexLabel().longId())) .map(Connection::getConnectionEdge) .forEach(edge -> { TypeDefinitionDescription desc = new TypeDefinitionDescription(TypeDefinitionCategory.CONNECTION_EDGE, newName); edge.property(BaseKey.SchemaDefinitionDesc.name(), desc); }); }
JanusGraphVertex oth = edge.vertex(dir.opposite()); assert oth instanceof JanusGraphSchemaVertex; TypeDefinitionDescription desc = edge.valueOrNull(BaseKey.SchemaDefinitionDesc); Object modifier = null; if (desc.getCategory().hasDataType()) {
public static RelationIdentifier getEdgeId(Object id) { if (null == id) return null; try { if (id instanceof JanusGraphEdge) return (RelationIdentifier) ((JanusGraphEdge) id).id(); else if (id instanceof RelationIdentifier) return (RelationIdentifier) id; else if (id instanceof String) return RelationIdentifier.parse((String) id); else if (id instanceof long[]) return RelationIdentifier.get((long[]) id); else if (id instanceof int[]) return RelationIdentifier.get((int[]) id); } catch (IllegalArgumentException e) { //swallow since null will be returned below } return null; }
@Test public void testEdgesExceedCacheSize() { // Add a vertex with as many edges as the tx-cache-size. (20000 by default) int numEdges = graph.getConfiguration().getTxVertexCacheSize(); JanusGraphVertex parentVertex = graph.addVertex(); for (int i = 0; i < numEdges; i++) { JanusGraphVertex childVertex = graph.addVertex(); parentVertex.addEdge("friend", childVertex); } graph.tx().commit(); assertCount(numEdges, parentVertex.query().direction(Direction.OUT).edges()); // Remove an edge. parentVertex.query().direction(OUT).edges().iterator().next().remove(); // Check that getEdges returns one fewer. assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); // Run the same check one more time. // This fails! (Expected: 19999. Actual: 20000.) assertCount(numEdges - 1, parentVertex.query().direction(Direction.OUT).edges()); }
assertEquals(v12, getOnlyElement(v.query().direction(Direction.OUT).labels("spouse").vertices())); edge = Iterables.getOnlyElement(v.query().direction(Direction.BOTH).labels("connect").edges()); assertEquals(1, edge.keys().size()); assertEquals("e1", edge.value("uid")); try { assertEquals(v12, getOnlyElement(v.query().direction(Direction.OUT).labels("spouse").vertices())); edge = Iterables.getOnlyElement(v.query().direction(Direction.BOTH).labels("connect").edges()); assertEquals(1, edge.keys().size()); assertEquals("e1", edge.value("uid")); try {
@Override public Iterable<JanusGraphEdge> getEdges(RelationIdentifier... ids) { verifyOpen(); if (ids==null || ids.length==0) return new VertexCentricEdgeIterable(getInternalVertices(),RelationCategory.EDGE); if (null != config.getGroupName()) { MetricManager.INSTANCE.getCounter(config.getGroupName(), "db", "getEdgesByID").inc(); } List<JanusGraphEdge> result = new ArrayList<>(ids.length); for (RelationIdentifier id : ids) { if (id==null) continue; JanusGraphEdge edge = id.findEdge(this); if (edge!=null && !edge.isRemoved()) result.add(edge); } return result; }
JanusGraphEdge e = d == OUT ? vertex.addEdge(n(label), vs[i]) : vs[i].addEdge(n(label), vertex); e.property("time", i); e.property("weight", i % 4 + 0.5); e.property("name", "e" + i); e.property("number", i % 5); int nowTime = e.value("time"); assertTrue(lastTime + " vs. " + nowTime, lastTime <= nowTime); lastTime = nowTime;
final JanusGraphEdge e = vs[random.nextInt(verticesPerTask)] .addEdge("l",vs[random.nextInt(verticesPerTask)]); e.property("t",random.nextInt(maxTime));
assertEquals(eid, getE(graph, eid).id());