Java usage of V() in updates on inmemory graph

조회수 23회
읽지 않은 첫 메시지로 건너뛰기

bremc...@ebay.com

읽지 않음,
2020. 5. 26. 오후 7:00:0720. 5. 26.
받는사람 JanusGraph users
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

읽지 않음,
2020. 5. 27. 오전 6:06:4320. 5. 27.
받는사람 janusgra...@googlegroups.com
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.

--
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 janusgraph-use...@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.

bre...@sidecourt.com

읽지 않음,
2020. 5. 27. 오전 11:34:3920. 5. 27.
받는사람 JanusGraph users
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.
전체답장
작성자에게 답글
전달
새 메시지 0개