How to print out Gremlin pipe / traversal results

感情迁移 提交于 2019-12-02 02:01:11

问题


I have the code below in a file named traversal.groovy (which I call from the command line with gremlin -e traversal.groovy):

// Begin traversal.groovy //

g = TinkerGraphFactory.createTinkerGraph()
v = g.v(1)

println v.outE.inV.name

// End traversal.groovy //

As you can see, it's very basic; but the output is not what I'm looking for. The output is

[StartPipe, OutEdgesPipe, InVertexPipe, PropertyPipe(name)]

When I run the same code in the gremlin command line, I get what I'm looking for...

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> v = g.v(1)
==>v[1]
gremlin> v.outE.inV.name
==>vadas
==>josh
==>lop

So, how do I access the information that I want that's somehow tucked away in [StartPipe, OutEdgesPipe, InVertexPipe, PropertyPipe(name)]? Thanks!


回答1:


Thanks to stephen mallette for pointing me in the right direction. To simply print out the "name" property of each vertex in my traversal above, we can use sideEffect and iterate. The resulting code would look as follows:

// Begin traversal.groovy //

g = TinkerGraphFactory.createTinkerGraph()
v = g.v(1)

v.outE.inV.sideEffect{println it.name}.iterate()

// End traversal.groovy //

and the output would be:

vadas
josh
lop



回答2:


You likely just need to iterate your pipeline:

http://gremlindocs.com/#methods/pipe-next

println v.outE.inV.name.next()


来源:https://stackoverflow.com/questions/15508599/how-to-print-out-gremlin-pipe-traversal-results

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!