MergeV in Go - setting the label
I am having a hard time finding any docs for the Go client, and the code itself does not reveal too much. I see some syntax magic for setting the label in Groovy, but I cannot work out what the equivalent is in Go.
Specifically, using:
g.MergeV(match).
Option(gremlingo.Merge.OnCreate, props).
Where match and props are [string]interface{} - how do I set the label type?
6 Replies
Hi jimidle,
Query can look like
<-g.MergeV(map[interface{}]interface{}{"some condition": 1}).Option(gremlingo.Merge.OnCreate, map[interface{}]interface{}{gremlingo.T.Label: "label1"}).Iterate()
Thank you Valentyn.
It seems my mistake was using map[string]interface{}, where I did indeed already have gremlingo.T.Label as a key. I guess I should explore why it needs to be map[interface{}] but that works as I expected once I changed my map definition.
Do you happen to know where there might be more examples? So far, I have been using the cucumber file gremlin.go, which is not too bad, but a bit of a trawl and did not immediately point to this.
OK - I see why an interface{} must be the key. Because gremlingo.T.Label is typed and I guess that the MergeV generates byte code for the Label by seeing that the property key is that type.
One thing here though is that if you want to use the same properties for OnMatch as OnCreate, you cannot because OnMatch gives an error about accepting only strings as keys and rejects the label. I was expecting it to merge the properties and maybe ignore the label
Vertex and Edge are immutable, therefore not possible to change Id or label. Only option is to drop old element and create new one with new id/label and same properties.
This is one of the reasons why OnCreate and OnMatch has different behavior
Understood. I wonder if t might be better for OnMatch to just ignore gremlingo.T.Label in the OnMerge property set. Otherwise I have to add it for create. Experimenting gave me this:
g.MergeV(match).As("d").
Option(gremlingo.Merge.OnMatch, props).
Option(gremlingo.Merge.OnCreate, AddLabel(props, "dial")).
Which works so long as the OnCreate step is listed after the OnMatch. Seems a bit hacky though. Maybe I should just dup the map and add the label on the dup for create.I agree that making a duplicate is better