0

I would like to traverse the graph until my node property value exist in the set. Set contains id of the nodes and trivial objects.

The query is like:

public Map<String,Object> getNodes( Long startNodeID, Set<String, TraversedNode> mySet){
      return g.withSideEffect("x",mySet).V(startNodeID)
             .repeat( ...something )
             .choose( ...something )
             .until( myProperty is found in the given set  )
}

I have tried many things in the until part but couldn't get it. Any suggestions to achieve? It maybe related to values and where keywords.

values("id").where(P.within("x")) doesn't work

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
yigi
  • 5
  • 2
  • It will help people to provide you tested answers if you can provide the `addV` and `addE` steps that build a small example graph. An example of building a sample graph can be found in the answer to this post https://stackoverflow.com/questions/73433016/gremlin-traverse-path-along-the-same-property/73449813#73449813 – Kelvin Lawrence Aug 28 '22 at 12:40
  • It will further help if, having provided the sample graph, you can also add an example of what the desired result should be. Unfortunately your question is a bit vague and any answer given will require the person answering to guess a bit as to what you are looking for. Is it just the IDs you want to find in the set, as you also mention properties? – Kelvin Lawrence Aug 28 '22 at 13:38
  • To hopefully advance the discussion, I added an initial answer below. – Kelvin Lawrence Aug 28 '22 at 19:15

1 Answers1

1

Using the air-routes graph as sample data, a simple query can be written that looks for IDs within a provided set, as the query progresses. As mentioned in the comments, it is not 100% clear if this is what you are looking for but perhaps it will help with follow on questions.

gremlin> g.withSideEffect('s',[48,54,62,12]).
......1>   V(44).
......2>   repeat(out().simplePath()).
......3>   until(where(within('s')).by(id).by()).
......4>   path().
......5>   limit(5)

==>[v[44],v[8],v[48]]
==>[v[44],v[8],v[54]]
==>[v[44],v[8],v[12]]
==>[v[44],v[13],v[12]]
==>[v[44],v[13],v[48]] 

It may appear that you should just be able to do until(hasId(within('s'))), but in that case 's' is treated as the literal string "s" and not a symbol representing the set called s. When a predicate is nested inside a where step, as in where(within('s')), Gremlin treats that as a special case and will treat s as the name of something declared earlier.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38