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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.