veekay33210
veekay33210

Reputation: 141

Tinkerpop/Gremlin Breadth first traversal

I'm trying to traverse a graph to trace the lineage of a specific node. I would like my query to yield the antecedents to that node in a breadth first pattern. Note, each node can have multiple parents. The Graph can be many layers deep and I'd like to see the results of all levels for a given node. I'm trying to follow along this recipe, but run into the exception No such property: gather. I'm trying this on the gremlin console version 3.3

Upvotes: 3

Views: 1413

Answers (1)

Jason Plurad
Jason Plurad

Reputation: 6782

Use a barrier() step (Apache TinkerPop 3.3 docs). For example:

gremlin> g.V().sideEffect{println "first: ${it}"}.barrier().sideEffect{println "second: ${it}"}.iterate()
first: v[1]
first: v[2]
first: v[3]
first: v[4]
first: v[5]
first: v[6]
second: v[1]
second: v[2]
second: v[3]
second: v[4]
second: v[5]
second: v[6]

Stephen gives another good description of BFS in this gremlin-users post.

First, let's assume a Gremlin language without optimization - doing:

g.V().out().out()

will result in a depth first search. You can force BFS with barrier():

g.V().out().barrier().out()

which basically will force the step prior to drain before moving on to the next step.

Upvotes: 3

Related Questions