Java usage of V() in updates on inmemory graph


bremc...@...
 

Hello,

Can someone kindly explain why the below example works without the red .V()? If that is included, the call to next() returns a NoSuchElementException.

static void example() throws Exception {
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
GraphTraversalSource g;

try {
g =
graph.traversal();
g.
V().addV().property("name", "marko").iterate();

g =
graph.traversal();
System.out.println("Got: " + g.V().has("name", "marko").next());

}
finally {
graph.close();
}
}


Stephen Mallette <spmal...@...>
 

On an empty graph I would expect 

g.V().addV()

to return NoSuchElementException and aside from rare cases I don't think you would typically write such a traversal. That traversal is basically saying "for ever vertex in the graph call add a new vertex". If the graph is empty then addV() will never be called. If on the other hand you use addV() as your start step rather than V(), the traversal stream is started with a newly added vertex and your code should work.

Also note that you do not need to keep instantiating "g". Create it once and re-use it.

On Tue, May 26, 2020 at 7:00 PM bremccarthy via JanusGraph users <janusgra...@...> wrote:
Hello,

Can someone kindly explain why the below example works without the red .V()? If that is included, the call to next() returns a NoSuchElementException.

static void example() throws Exception {
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
GraphTraversalSource g;

try {
g =
graph.traversal();
g.
V().addV().property("name", "marko").iterate();

g =
graph.traversal();
System.out.println("Got: " + g.V().has("name", "marko").next());

}
finally {
graph.close();
}
}

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgra...@....
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/3be399a3-983c-418b-a82d-021cbbd6ff67%40googlegroups.com.


bre...@...
 

Perfect. Thanks for your explanation!


On Wednesday, May 27, 2020 at 3:06:43 AM UTC-7, Stephen Mallette wrote:
On an empty graph I would expect 

g.V().addV()

to return NoSuchElementException and aside from rare cases I don't think you would typically write such a traversal. That traversal is basically saying "for ever vertex in the graph call add a new vertex". If the graph is empty then addV() will never be called. If on the other hand you use addV() as your start step rather than V(), the traversal stream is started with a newly added vertex and your code should work.

Also note that you do not need to keep instantiating "g". Create it once and re-use it.

On Tue, May 26, 2020 at 7:00 PM bremccarthy via JanusGraph users <janusgra...@googlegroups.com> wrote:
Hello,

Can someone kindly explain why the below example works without the red .V()? If that is included, the call to next() returns a NoSuchElementException.

static void example() throws Exception {
JanusGraph graph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
GraphTraversalSource g;

try {
g =
graph.traversal();
g.
V().addV().property("name", "marko").iterate();

g =
graph.traversal();
System.out.println("Got: " + g.V().has("name", "marko").next());

}
finally {
graph.close();
}
}

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/3be399a3-983c-418b-a82d-021cbbd6ff67%40googlegroups.com.