Selecting a single value from a map

1,043 views
Skip to first unread message

Robert Dale

unread,
Jun 28, 2017, 3:46:15 PM6/28/17
to gremli...@googlegroups.com

Trying to use a value from a traversal induced map.

Many things are possible to select from (or do to) a map, but the ability to select single value by key seems to be absent.

{code}
g = TinkerGraph.open().traversal()
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').select(keys)
==>[name,age]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').select(values)
==>[marko,100]
gremlin> g.inject(['name':'marko','age':100]).as('a').select(first,'a')
==>[name:marko,age:100]
gremlin> g.inject(['name':'marko','age':100]).as('a').select(last,'a')
==>[name:marko,age:100]
gremlin> g.inject(['name':'marko','age':100]).as('a').select(all,'a')
==>[[name:marko,age:100]]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').map(values('name'))
java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').values('name')
java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').by(values('name'))
java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
Type ':help' or ':h' for help.
Display stack trace? [yN]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').by('name')
java.util.LinkedHashMap cannot be cast to org.apache.tinkerpop.gremlin.structure.Element
Type ':help' or ':h' for help.
Display stack trace? [yN]

gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').order().by(keys)
==>[name:marko,age:100]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').order().by(values)
==>[name:marko,age:100]
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').range(local,0,1)
==>[name:marko]

{code}

Seems like by() and/or values() should be able to figure out it's taking a map and select that key.

Am I missing something or should I create a ticket?


Robert Dale

Stephen Mallette

unread,
Jun 29, 2017, 7:41:42 AM6/29/17
to Gremlin-users
I'm not sure if I've run into that specific issue before, but I've had problems with map manipulation too (not sure if there is a trick to solving your problems). As a larger issue, if we want to push users towards selecting just the data they want (as opposed to returning an entire Vertex/Edge) we probably need to be sure that Gremlin can work seamlessly with maps.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CABed_4pSjZ_fjB2LRtuBn8Fikiyx%3DRmVZWO1dZX3j%3DYrPFvA3A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Robert Dale

unread,
Jun 29, 2017, 8:19:57 AM6/29/17
to gremli...@googlegroups.com
Figured it out by accident. It appears that select() actually does check the traversal for a map first and if it exists, selects that key. Otherwise, select will pick the labelled step.  Thus,

gremlin> g.inject(['name':'marko','age':100]).select('name')
==>marko
gremlin> g.inject(['name':'marko','age':100]).as('name').select('name')
==>marko
gremlin> g.inject(['name':'marko','age':100]).as('a').select('a').select('name')
==>marko
gremlin> g.inject(['name':'marko','age':100]).as('a').select('name')
==>marko

Ultimately, this now works:
g.inject(['name':'marko','age':100]).as('a').addV('person').property('name', select('a').select('name')).property('age',select('a').select('age'))





Robert Dale

Stephen Mallette

unread,
Jun 29, 2017, 8:27:58 AM6/29/17
to Gremlin-users
good....i wish I'd better tracked some of my problems working with maps. i plan to pay more attention going forward given HaltedTraverserStrategy/Reference stuff.

Reply all
Reply to author
Forward
0 new messages