Aggregating vertices with set-cardinality properties
I am aggregating traversed vertices that have both single and set-cardinality properties. When capturing the vertex using
elementMap()
it assumes a single-cardinality for all properties and only considers the last element in the set when building the map.
However, when trying to use valueMap(true).by(unfold())
(as described in this SO reply: https://stackoverflow.com/a/75225994/3516889)
It just gives the last property value in the set.
query using valueMap(true).by(unfold())
(1):
Query 1 returns only the first-added sample:
Query Using elementMap()
(2):
Query 2 returns only the last-added sample:
What I need is the following result:
I tried playing with local()
but I can't seem to get a proper map of the elements with a set-cardinality property.
Appreciate your help!Stack Overflow
Valuemap returns array
In Tinkerpop3 valueMap is returning an array, how can I get a real key value pair (without Array)?
gremlin> Gremlin.version()
==>3.0.1-incubating
:> def trav = g.V().hasLabel('Group'); t...
8 Replies
I think it's typically easiest to use
project()
in these cases:
There's no way to selectively make valueMap()
(or elementMap()
for that matter) choose multiproperties or single. There is probably some Gremlin that could be written to transform the results of valueMap()
to the form you like, but that Gremlin is a bit harder to read compared to the simplicity of project()
. it looks like this:
basically, you take each Map
and deconstruct it with unfold()
to entries, then for each entry you do an if/then on the keys
to see if it is a "name" property and if it is you unfold()
that to a single item, otherwise you just use the values
as-is in a list form.Thanks @spmallette
I was able to adjust the last suggestion to make it work the way I was expecting (I need the element Id and Label as well).
Unfortunately I couldn't figure out how to include this information with
project(...)
This is the query I ended up with:
oh i see that map(...)
is replaced by local(...)
in my example but this means that that the result is the same in my tests. I was just tinkering with the query...careful with
local()
- it is not interchangeable with map()
exactly: https://stephen.genoprime.com/snippet/2023/04/13/snippet-15.html as for:
Unfortunately I couldn't figure out how to include this information with project(...)you could just add them to the
project()
like:
stephen mallette
Use of local() Revisited
In recent weeks there have been many questions about the local()-step both in Discord and in TinkerPop’s JIRA. I’d written on this topic once before in Use of local() but it perhaps begs a further revisit. The example that arose from Discord helped inspire this post as it was sufficiently primitive to hopefully clarify usage.
Whoa, thanks for the warning about
local
!
Regarding vlabel
and vid
, looks like they are not returned from AWS Neptune.
@spmallettereally? that's strange....what if you replace those last lines with:
does that make a difference?
apologies, I copy-paste issue on my part. I wrapped the parameters in by('id') when it should just be
by(id)
so, perfect, this works!
I'm curious though, in the *least-favorable solution you shared there is filter referencing keys
and values
:
Do they exist in the Java Client? I can't find __.keys()
but thre are __.key()
and __.values()
They are part of the
Column
enumYou're a saint! Thanks!