I have been working with Apache Tinkerpop 3.3 in a Java environment and I have been having trouble printing the output of the queries I make. For example, when I use the following code:
GraphTraversalSource g = tg.traversal();
System.out.println(g.V(V1).in().values().fold());
The output I get is just the description of the action (something like this).
[GraphStep(vertex,[v[0]]), VertexStep(IN,vertex)]
I have tried adding .toList() but it still doesn't work. I have gone through the documentation of TinkerPop but it hasn't been of much help. What can I do to actually print the output of the query (in this case, the list of vertices connected to the Vertex V1) on the screen?
Thank you!
When you do:
System.out.println(g.V(V1).in().values().fold());
you are printing the Traversal
instance itself and not the result. The result needs to be iterated out in some way - result iteration is described in some detail in The Gremlin Console Tutorial.
Now, you do say that you that you appended .toList()
to the end of that traversal, so I'm not sure why you would still have a problem if your code looked like this:
System.out.println(g.V(V1).in().values().fold().toList());
Though this should probably be all you need since fold()
is already returning a single List
:
System.out.println(g.V(V1).in().values().fold().next());
I would validate that your traversal actually returns data, as either of the above should show your output.