@Override public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { if (memory.isInitialIteration()) { if (vertex.id().equals(Long.valueOf(seed).longValue())) { // The seed sends a single message to start the computation log.debug("Sent initial message from {}", vertex.id()); // The seed's distance to itself is zero vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L); messenger.sendMessage(incidentMessageScope, 0L); } } else { Iterator<Long> distances = messenger.receiveMessages(); // Find minimum distance among all incoming messages, or null if no messages came in Long shortestDistanceSeenOnThisIteration = IteratorUtils.stream(distances).reduce((a, b) -> Math.min(a, b)).orElse(null); if (null == shortestDistanceSeenOnThisIteration) return; // no messages to process or forward on this superstep VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE); if (!currentShortestVP.isPresent() || currentShortestVP.value() > shortestDistanceSeenOnThisIteration) { // First/shortest distance seen by this vertex: store it and forward to neighbors vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration); messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration); } // else: no new winner, ergo no reason to send message to neighbors } }
@Override public void execute(final Vertex vertex, Messenger<Long> messenger, final Memory memory) { if (memory.isInitialIteration()) { if (vertex.id().equals(seed)) { // The seed sends a single message to start the computation log.debug("Sent initial message from {}", vertex.id()); // The seed's distance to itself is zero vertex.property(VertexProperty.Cardinality.single, DISTANCE, 0L); messenger.sendMessage(incidentMessageScope, 0L); } } else { Iterator<Long> distances = messenger.receiveMessages(); // Find minimum distance among all incoming messages, or null if no messages came in Long shortestDistanceSeenOnThisIteration = IteratorUtils.stream(distances).reduce(Math::min).orElse(null); if (null == shortestDistanceSeenOnThisIteration) return; // no messages to process or forward on this superstep VertexProperty<Long> currentShortestVP = vertex.property(DISTANCE); if (!currentShortestVP.isPresent() || currentShortestVP.value() > shortestDistanceSeenOnThisIteration) { // First/shortest distance seen by this vertex: store it and forward to neighbors vertex.property(VertexProperty.Cardinality.single, DISTANCE, shortestDistanceSeenOnThisIteration); messenger.sendMessage(incidentMessageScope, shortestDistanceSeenOnThisIteration); } // else: no new winner, ergo no reason to send message to neighbors } }
@Override public boolean isPresent() { return this.baseVertexProperty.isPresent(); }
@Override public boolean isPresent() { return this.getBaseVertexProperty().isPresent(); }
@Override public void map(final Vertex vertex, final MapEmitter emitter) { assertFalse(vertex.property("v1").isPresent()); assertFalse(vertex.property("v2").isPresent()); assertTrue(vertex.property("v3").isPresent()); assertTrue(vertex.property("name").isPresent()); assertEquals(3, IteratorUtils.count(vertex.properties())); assertEquals(3, IteratorUtils.count(vertex.values())); }
@Override public void addStart(final Traverser.Admin<Vertex> start) { final VertexProperty<TraverserSet<Object>> property = start.get().<TraverserSet<Object>>property(TraversalVertexProgram.HALTED_TRAVERSERS); this.count = property.isPresent() ? property.value().bulkSize() : 0l; }
@Override public <V> VertexProperty<V> property(final String key) { final VertexProperty<V> vertexProperty = getBaseVertex().<V>property(key); return vertexProperty.isPresent() ? new HadoopVertexProperty<>((VertexProperty<V>) ((Vertex) this.baseElement).property(key), this) : VertexProperty.<V>empty(); }
private boolean isStartVertex(final Vertex vertex) { // use the sourceVertexFilterTraversal if the VP is running in standalone mode (not part of a traversal) if (this.standalone) { final Traversal.Admin<Vertex, ?> filterTraversal = this.sourceVertexFilterTraversal.getPure(); filterTraversal.addStart(filterTraversal.getTraverserGenerator().generate(vertex, filterTraversal.getStartStep(), 1)); return filterTraversal.hasNext(); } // ...otherwise use halted traversers to determine whether this is a start vertex return vertex.property(TraversalVertexProgram.HALTED_TRAVERSERS).isPresent(); }
@Test public void testEliminateAndEliminateDifferentVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "age", 18, "name", "Tom", "lived", "Beijing"); vertex.property("age").remove(); vertex.property("lived").remove(); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("age").isPresent()); Assert.assertFalse(vertex.property("lived").isPresent()); }
@Test @LoadGraphWith(MODERN) public void g_V_programXpageRankX() { final Traversal<Vertex, Vertex> traversal = get_g_V_programXpageRankX(); printTraversalForm(traversal); int counter = 0; while (traversal.hasNext()) { final Vertex vertex = traversal.next(); counter++; assertTrue(vertex.property(PageRankVertexProgram.PAGE_RANK).isPresent()); } assertEquals(6, counter); }
@Test public void testInsertAndEliminateVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); }
@Test public void testAppendAndEliminateSameVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Shanghai"); vertex.property("lived").remove(); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); }
@Test public void testEliminateAndEliminateSameVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.property("lived").remove(); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); }
@Test public void testAppendAndInsertVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived", "Wuhan"); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test public void testAppendAndEliminateDifferentVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("name", "Tomcat"); vertex.property("lived").remove(); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); Assert.assertEquals("Tomcat", vertex.property("name").value()); }
@Test public void testEliminateAndAppendDifferentVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.property("name", "Tomcat"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertFalse(vertex.property("lived").isPresent()); Assert.assertEquals("Tomcat", vertex.property("name").value()); }
@Test public void testEliminateAndAppendSameVertexProperty() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); vertex.property("lived", "Shanghai"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test public void testEliminateAndInsertVertex() { HugeGraph graph = graph(); Vertex vertex = graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); vertex.property("lived").remove(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); graph.tx().commit(); vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }
@Test @LoadGraphWith(MODERN) public void shouldFailWithImproperTraverserRequirements() throws Exception { final VertexProgramQ vp = VertexProgramQ.build().property("pl").useTraverserRequirements(false).create(); try { g.V().repeat(__.out()).emit().program(vp).dedup() .forEachRemaining((Vertex v) -> assertFalse(v.property("pl").isPresent())); } catch (VerificationException ex) { assumeNoException(ex); } }
@Test public void testDeleteAndInsertVertex() { HugeGraph graph = graph(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Beijing"); graph.traversal().V().hasLabel("author").has("id", 1).next().remove(); graph.addVertex(T.label, "author", "id", 1, "name", "Tom", "lived", "Shanghai"); graph.tx().commit(); Vertex vertex = vertex("author", "id", 1); Assert.assertTrue(vertex.property("lived").isPresent()); Assert.assertEquals("Shanghai", vertex.property("lived").value()); }