Does the TinkerGraph in-memory database support List cardinality properties for vertices?
It is my understanding that the following code should work:
The output when this is executed is:
However, I would expect its output to be something like this:
Does anyone know what I am doing wrong here?
Solution:Jump to solution
elementMap()
assumes that cardinality for each key is single and if it is list then only the first item encountered will be returned.
To get all property values valueMap()
step can be used instead.
`gremlin> g.V(1).property("address", "a1").property(list, "address", "a2")
==>v[1]
gremlin> g.V(1).valueMap()...6 Replies
Solution
elementMap()
assumes that cardinality for each key is single and if it is list then only the first item encountered will be returned.
To get all property values valueMap()
step can be used instead.
gremlin> g.V(1).property("address", "a1").property(list, "address", "a2")
==>v[1]
gremlin> g.V(1).valueMap()
==>[address:[a1,a2],name:[marko],age:[29]]
gremlin> g.V(1).elementMap()
==>[id:1,label:person,address:a2,name:marko,age:29]
Thanks for that! This wasted a lot of my time, though...😫
I just checked the javadoc and other documentation and found no mention of this. Is this documented anywhere? I am happy to do it...
I think in the elementMap description it is documented. Having two similar functions are very confusing.
I think best sources are official docs https://tinkerpop.apache.org/docs/current/reference/#valuemap-step
and Kelvin's book https://kelvinlawrence.net/book/Gremlin-Graph-Guide.html#element-map
the need for two steps arose from the issue where
valueMap()
creates a structure that is complicated to work with. for the most part, property values are Cardinality.single
so for valueMap()
to always return a List
always tended to confuse folks. we eventually changed valueMap()
so that you could do valueMap().by(unfold())
to unwrap the value (which was better than deconstructing and reconstructing the Map
), but folks tended to find that unsatisfactory as well because the intent isn't really clear. It was at that point that we decided to do elementMap()
so that there was a clear step that explicitly gave folks what they want as output.Interesting history. Can’t please everyone :gremlin_smile: