Does Gremlin "loop" throw away the objects in the pipeline and start again?

23 views
Skip to first unread message

Neil Barnwell

unread,
Mar 5, 2012, 11:37:37 AM3/5/12
to ne...@googlegroups.com
I'll describe in Cypher (as best I can) because it's easiest to write up the graph that I have.

I have a graph thus:

RootNode-[:hosts]->Container-[:contains]->Container-[:contains]->Container-[:contains]->Item
                            -[:contains]->Item


The first container "hierarchy" here describes vehicles containing cages containing boxes containing items. As such there are two Items in my graph, Item1 is in a box in a cage in a vehicle while Item2 is loose and floating around in the vehicle not in a box or cage at all.

The following Gremlin query "compiles" for me (this is a huge milestone for me):

g.V.out('hosts').as('contained').out('contains').loop('contained'){true}

Unfortunately it returns no items. If I change the loop condition to "it.loops<4" then I only get one result - for Item1.

My ultimate goal is to find all "leaves" i.e. Items. I'm trying to build the query one step at a time but I'm no longer confident again about how "loop" actually works with respect to maintaining the objects passed-in to it.

Marko Rodriguez

unread,
Mar 5, 2012, 1:17:21 PM3/5/12
to ne...@googlegroups.com

Hi,

loop{true} will loop itself right off the tree! I suspect you will want make use of an emit closure if you want to see everything you touch (for instance) or update your loop closure if you just want the leaves. E.g for the prior:

...loop(...){true}{true}

For the latter:

...loop(...){it.object.out.count() == 0}

HTH,
Marko.

http://markorodriguez.com

Marko Rodriguez

unread,
Mar 5, 2012, 1:19:43 PM3/5/12
to ne...@googlegroups.com

Sorry, I mean {it.object.out.count() != 0}. The semantics are 'while', so loop while there are still children to traverse to.

Marko.

http://markorodriguez.com

Reply all
Reply to author
Forward
0 new messages