How to print out Gremlin pipe / traversal results

前端 未结 2 1236
春和景丽
春和景丽 2021-01-22 16:09

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

// Beg         


        
2条回答
  •  抹茶落季
    2021-01-22 16:32

    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
    

提交回复
热议问题