'How to recursively search UP a Gremlin TinkerPop tree using Until and In

I have a TinkerPop Graph on a Gremlin Server and I'm trying to recursively search up a tree from a leaf until I can get to the root.

Given a tree that looks like this enter image description here I can query Items and Packages off of a known Shipment via this.

g.V("MyShipment").repeat(out().not(hasLabel("contracted", "contains")).simplePath()).until(outE().count().is(0)).path()

However trying to do the reverse fails

g.V("MyItem2").repeat(in().not(hasLabel("contracted", "contains")).simplePath()).until(inE().count().is(0)).path()

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script61.groovy: 1: unexpected token: in @ line 1, column 23. g.V("MyItem2").repeat(in().not(hasLabel("contracted","contains")).simplePath()).until(inE().count().is(0)).path() ^

1 error

Is there anyway to recursively look up a tree via In Edges?



Solution 1:[1]

The in keyword is a reserved word in Groovy. Try using

g.V("MyItem2").
  repeat(__.in().not(hasLabel("contracted","contains")).simplePath()).
  until(inE().count().is(0)).
  path()

Note that you can also write the query as

g.V("MyItem2").
  repeat(__.in().not(hasLabel("contracted","contains")).simplePath()).
  until(__.not(__.in())).
  path()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kelvin Lawrence