You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by Per Bergman <no...@gmail.com> on 2017/03/13 15:02:48 UTC

collecting properties from traversal?

I have a tree, where each Vertex has a 'parent' edge. From a leaf I need to construct the path to the root, something like:

g.V("PUBLIC.Node:::13").repeat(out('parent')).until(out('parent').count().is(0)).path()) 

(or .tree())


What I need is to collect all properties from each Vertex in a list, while traversing.
Should I use a sack() or sideEffects(), or something else?


Thanks,
Per


Re: collecting properties from traversal?

Posted by Daniel Kuppitz <me...@gremlin.guru>.
The obvious solution is this:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V(5).repeat(__.in()).emit(__.not(inE())).path()
==>[v[5],v[4],v[1]]
gremlin>
g.V(5).repeat(__.in()).emit(__.not(inE())).path().unfold().valueMap()
==>[name:[ripple],lang:[java]]
==>[name:[josh],age:[32]]
==>[name:[marko],age:[29]]
gremlin>
g.V(5).repeat(__.in()).emit(__.not(inE())).path().unfold().properties()
==>vp[name->ripple]
==>vp[lang->java]
==>vp[name->josh]
==>vp[age->32]
==>vp[name->marko]
==>vp[age->29]

However, you don't need the path requirement, instead you can aggregate all
properties in a side-effect.

gremlin> g.V(5).sideEffect(properties().aggregate("x")).
           repeat(__.in().sideEffect(properties().aggregate("x"))).
             emit(__.not(inE())).cap("x")
==>[vp[name->ripple],vp[lang->java],vp[name->josh],vp[age->32],vp[name->marko],vp[age->29]]

Cheers,
Daniel



On Mon, Mar 13, 2017 at 4:02 PM, Per Bergman <no...@gmail.com> wrote:

>
> I have a tree, where each Vertex has a 'parent' edge. From a leaf I need
> to construct the path to the root, something like:
>
> g.V("PUBLIC.Node:::13").repeat(out('parent')).until(
> out('parent').count().is(0)).path())
>
> (or .tree())
>
>
> What I need is to collect all properties from each Vertex in a list, while
> traversing.
> Should I use a sack() or sideEffects(), or something else?
>
>
> Thanks,
> Per
>
>