James Render
James Render

Reputation: 1590

How do I collect values from a vertex used in a traversal?

I want the details of a vertex along with details of vertices that are joined to it.

I have a group vertex, incoming 'member' edges to user vertices. I want the details of the vertices.

g.V(1).as('a').in('member').valueMap().as('b').select('a','b').unfold().dedup()

==>a=v[1]
==>b={image=[images/profile/friend9.jpg], name=[Thomas Thompson], email=[[email protected]]}
==>b={image=[images/profile/friend13.jpg], name=[Laura Tostevin], email=[[email protected]]}
==>b={image=[images/profile/friend5.jpg], name=[Alan Thompson], email=[[email protected]]}
==>b={image=[images/profile/friend10.jpg], name=[Laura Bourne], email=[[email protected]]}

Ideally what I'd want is:

{label: 'group', id=1, name='A Group', users=[{id=2, label="user",name=".."}, ... }]}

When I tried a project, it didn't like me using 'in'

gremlin> g.V('1').project('name','users').by('name').by(in('member').select()) groovysh_parse: 1: unexpected token: in @ line 1, column 83. 'name','users').by('name').by(in('member

Upvotes: 2

Views: 93

Answers (2)

noam621
noam621

Reputation: 2856

Because in is a reserved keyword in Groovy you must use the verbose syntax __.in

try:

g.V('1').project('name','users').by('name').by(__.in('member').valueMap(true).fold())

Upvotes: 1

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

To get your preferred output format, you have to join the group's valueMap() with the list of users. On TinkerPop's modern toy graph you would do something like this:

gremlin> g.V(3).union(valueMap(true).
                        by(unfold()), 
                      project('users').
                        by(__.in('created').
                           valueMap(true).
                             by(unfold()).
                           fold())).
                unfold().
                group().
                  by(keys).
                  by(select(values))
==>[name:lop,id:3,lang:java,label:software,users:[[id:1,label:person,name:marko,...],...]]

Mapping this to your graph should be pretty straight-forward, it's basically just about changing labels.

Upvotes: 3

Related Questions