Gremlin python MergeV update properties
I'm working with gremlin python 3.7.1 and AWS Neptune 1.3.2.1, and I'm trying to update vertex properties with MergeV().option(OnMatch, {...}), however the behavior isn't what I expect, it should be a=b but appears to be a=[c.b] where c is the old value. Someone knows how to implement correctly this behavior with MergeV?
Solution:Jump to solution
If I'm understanding your question correctly, I think what you are seeing is a result of Neptune defaulting to
set
cardinality for properties. Essentially what that means, is if I start with a vertex with property("name", "Alice")
, and I try to overwrite the property with property("name", "Bob")
Neptune will instead add the new property to a set such that vertex.name = {"Alice", "Bob"}
. I think this is what you are seeing this set cardinality behaviour when using MergeV().
If you want to use mergeV and enforce single cardinality for properties (overwrite existing values instead of appending), you can try a query like this:
```...6 Replies
Solution
If I'm understanding your question correctly, I think what you are seeing is a result of Neptune defaulting to
set
cardinality for properties. Essentially what that means, is if I start with a vertex with property("name", "Alice")
, and I try to overwrite the property with property("name", "Bob")
Neptune will instead add the new property to a set such that vertex.name = {"Alice", "Bob"}
. I think this is what you are seeing this set cardinality behaviour when using MergeV().
If you want to use mergeV and enforce single cardinality for properties (overwrite existing values instead of appending), you can try a query like this:
ahhh thats the answer I need, thank you so much
hmmm it appears this error when i tried to implement.
and the dict looks like this
That's strange, I'm able to run the exact query I shared above with gremlin python 3.7.1 and Neptune 1.3.2.1. Could I ask you to double check the versions you are using here?
The syntax I shared above is a relatively recent addition to TinkerPop (3.7.0) (docs), the error you are seeing seems consistent with what I would expect from an older server which does not yet support the syntax to set individual cardinalities on each property.
I'm not recognizing what that dict represents. Where are you extracting that dict from? It might be helpful if you could share the full query you are attempting to run (with any sensitive property keys and values replaced with dummy values).
ohhh you right, i was using the wrong engine version, i was using Neptune 1.3.1.0
In that case, none of the new syntax to specify cardinalities in property maps is supported. If upgrading your Neptune is an option for you, it looks like 1.3.2.0 is the earliest which supports the new syntax. https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-client.html
If you are stuck on the older version, a query such as this might work for you:
I don't like recommending to use a query such as this as it's really abusing the ability to pass a sub-traversal to produce a map, to instead modify the matched vertex directly. This wasn't how mergeV was intended to be used but it might solve your issue.
Java-based Gremlin clients to use with Amazon Neptune - Amazon Neptune
You can use either of two open-source Java-based Gremlin clients with Amazon Neptune: the Apache TinkerPop Java Gremlin client , or the Gremlin client for Amazon Neptune .