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

104 views
Skip to first unread message

James Render

unread,
Jul 8, 2019, 6:53:02 AM7/8/19
to Gremlin-users

Sorry for posting another query question, bamboozled with all the language features.  I'm struggling with 'collecting stuff as I go along 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=[me@thomasthompson.co.uk]}
==>b={image=[images/profile/friend13.jpg], name=[Laura Tostevin], email=[me@lauratostevin.co.uk]}
==>b={image=[images/profile/friend5.jpg], name=[Alan Thompson], email=[me@alanthompson.co.uk]}
==>b={image=[images/profile/friend10.jpg], name=[Laura Bourne], email=[me@laurabourne.co.uk]}

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
                                 ^



James Render

unread,
Jul 8, 2019, 8:39:19 AM7/8/19
to Gremlin-users

Kelvin Lawrence

unread,
Jul 8, 2019, 10:14:23 AM7/8/19
to Gremlin-users
in() is one of those pesky Groovy reserved words.

try using __.in() instead  - that's two underscore characters

Cheers
Kelvin

James Render

unread,
Jul 8, 2019, 10:47:53 AM7/8/19
to Gremlin-users
No, I don't think it's that in this instance. My mistake, sorry, red herring. It's the use of `select()` inside the `by()` modifier.

gremlin> :> g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member'))
==>{name=Keyboard Deniers, users=v[12a5ffcf-16c8-4374-9ed7-6909d0032de3]}


gremlin> :> g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member').select())
{"requestId":"8977b51a-4764-4329-8480-64de25e43d0b","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 110, error message : no viable alternative at input 'g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member').select()'"}

Trying to figure out how to get all the user details out of the 2nd by.  The closet that I've gotten is:

gremlin> :> g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member').group().by(id).by('name'))
==>{name=Keyboard Deniers, users={26c97989-3ed4-4531-970e-cc56a4116a81=[Tony Van Lindholm], de041002-8bd8-4fa6-b42f-bff4eb315753=[Laura Bourne], ...}}

I'd like it to be a list of the user values.. but if I try a second project doesn't like it:

gremlin> :> g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member').project().by(id).by('name'))
{"requestId":"428aab5b-990c-453f-923f-d6648fc6f9d7","code":"MalformedQueryException","detailedMessage":"Query parsing failed at line 1, character position at 111, error message : no viable alternative at input 'g.V().hasId('119cfde8-7a7a-437e-a0d6-5c09483811ff').project('name','users').by('name').by(in('member').project()'"}


James Render

unread,
Jul 9, 2019, 7:03:15 AM7/9/19
to Gremlin-users
sorry, I was being a numpty and doing `__in()` rather than `__.in()`

that combined with a `valueMap().fold()` has gotten me there.

thanks for your help
Reply all
Reply to author
Forward
0 new messages