.valueMap() is generating {"key" => ArrayList("value")}

891 views
Skip to first unread message

Steven Tang

unread,
Feb 2, 2016, 1:19:14 PM2/2/16
to Gremlin-users
I'm in the process of upgrading from 0.5.4 to 1.0 and am looking for the replacement for the .map() function (in Java)

We used to be able to .map() at the end of a query and then pipe that to a .toList() and we'd end up with key value pairs like you would expect

{"id" : 1, "name" : "marko"}

but now I'm getting this:

{"id" : [1], "name" : ["marko"]}

Screenshot attached
Screen Shot 2016-02-02 at 10.08.30 AM.png

Daniel Kuppitz

unread,
Feb 2, 2016, 3:57:45 PM2/2/16
to gremli...@googlegroups.com
That's the expected behavior. See http://tinkerpop.incubator.apache.org/docs/3.0.2-incubating/#valuemap-step to learn why it's implemented this way.

Cheers,
Daniel


--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/810d029e-d1eb-48d3-9bc1-122f69e4f21f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Tang

unread,
Feb 2, 2016, 4:12:30 PM2/2/16
to Gremlin-users
Is there a way to unwrap the values from the array within the query, or does that have to be done outside the context of a traversal?

Daniel Kuppitz

unread,
Feb 2, 2016, 4:44:34 PM2/2/16
to gremli...@googlegroups.com
gremlin> Gremlin.version()
==>3.1.1-SNAPSHOT
gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().valueMap()
==>[name:[marko], age:[29]]
==>[name:[vadas], age:[27]]
==>[name:[lop], lang:[java]]
==>[name:[josh], age:[32]]
==>[name:[ripple], lang:[java]]
==>[name:[peter], age:[35]]

gremlin> g.V().local(properties().group().by(key()).by(value()))
==>[name:marko, age:29]
==>[name:vadas, age:27]
==>[name:lop, lang:java]
==>[name:josh, age:32]
==>[name:ripple, lang:java]
==>[name:peter, age:35]

Should also work with a slightly older version. Let me know if not.

Cheers,
Daniel


Gaurav Nolkha

unread,
Dec 5, 2016, 8:10:34 PM12/5/16
to Gremlin-users

This is what I'm getting on 3.0.1-incubating:


gremlin> Gremlin.version()

==>3.0.1-incubating


gremlin> :> def trav = g.V().hasLabel('Group'); trav.local(properties().group().by(key()).by(value()))

==>{joinTime={2016-12-05T22:27:01.088Z=1}, groupId={60e76537-9de5-45cf-b40d-e357b40e87b1=1}, mCanInvite={true=1}}


Why does it give me =1 ??

Daniel Kuppitz

unread,
Dec 5, 2016, 8:38:02 PM12/5/16
to gremli...@googlegroups.com
What you see is a BulkSet. I don't have a test environment for 3.0.1, but you can try this:

...local(properties().group().by(key()).by(value().unfold()))

Pretty sure this will give you the same format that we have in newer versions.

Cheers,
Daniel


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/b9ef34c7-83c4-42fd-9556-c920fa303615%40googlegroups.com.

Gaurav Nolkha

unread,
Dec 5, 2016, 9:48:02 PM12/5/16
to Gremlin-users

:(


gremlin> :> def trav = g.V().hasLabel('Group'); trav.local(properties().group().by(key()).by(value().unfold()))

==>{groupId={4612-4e6a-8f0a-c0645c0631ec=1}, mCanInvite={true=1}, ....}}

Reply all
Reply to author
Forward
0 new messages