TinkerGraph g = TinkerGraph.open();
g.createIndex("userId", Vertex.class);
GraphTraversalSource tg = g.traversal();
....
populate graph
....
System.out.println(tg.V().has("userId", "1234").values("name")); // how do I print out value of "name" ?
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/d3d0074c-bad8-4e5a-bde7-9152b8c3fc8e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public void buildGraph(){
List<Employee> employees = .. get from source
TinkerGraph g = TinkerGraph.open();
g.createIndex("userId", Vertex.class);
GraphTraversalSource tg = g.traversal();
employees.stream().filter(Objects::nonNull).forEach(e -> {
Vertex v1 = getOrCreate(tg, g, e.getEmpId());
v1.properties("name", e.getFirstName());
if(e.getReportsTo() != null){
Vertex v2 = getOrCreate(tg, g, e.getReportsTo());
v1.addEdge("reportsTo", v2);
}
});
Vertex it = tg.V().has("userId", "1234").next();
String val = it.value("name");
System.out.println(val);
}
private Vertex getOrCreate(GraphTraversalSource tg, Graph g, String eId){
GraphTraversal<Vertex, Vertex> t = tg.V().has("person", "userId", eId);
return t.hasNext() ? t.next() : tg.addV("person").property("userId", eId).next();
}
I think you just need to iterate your traversal:or more simply:System.out.println(tg.V().has("userId", "1234").values("name").next())
On Fri, Dec 29, 2017 at 11:08 AM, 'Rahul' via Gremlin-users <gremli...@googlegroups.com> wrote:
HelloI am able to populate the in-memory TinkerGraph using Java. Now I am trying to query the graph and print results of the query in console. But I am struggling to do simple Java operations. Most of the documentation/tutorial online gives example using Groovy and unfortunately I don't know Groove yet.TinkerGraph g = TinkerGraph.open();
g.createIndex("userId", Vertex.class);
GraphTraversalSource tg = g.traversal();
....
populate graph
....
System.out.println(tg.V().has("userId", "1234").values("name")); // how do I print out value of "name" ?So values() method returns GraphTraversal which I believe is to chain subsequent queries. But how do I get actual value from GraphTraversal ? I apologize if this is too simple question to ask.Thanks!
--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
v1.properties("name", e.getFirstName()); -> v1.property("name", e.getFirstName());
v1.property("firstName", e.getFirstName()).property("lastName", e.getLastName());
System.out.println(v1.values("firstName").next()); // WORKS
System.out.print(" " + v1.values("lastName").next()); //THROWS java.util.NoSuchElementException
v1.property("firstName", e.getFirstName()).property("lastName", e.getLastName()); v1.property("firstName", e.getFirstName());
v1.property("lastName", e.getLastName());
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/9b1a7a55-0cf6-4261-9f90-4c3905df4d3b%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.