mergeE(): increment counter on match
Hi, is there an easy way to increment an existing edge property based on its current value using
mergeE()
in one single query? (e.g., counter += 1
)
Something similar to this:
where X
is the current value of edge propery num_calls
.11 Replies
BTW, I was able to obtain the result I need with a query that looks like this:
but I'm wondering how something similar can be done with
mergeE()
I think this is impossible now.
@spmallette, do you think this is a good use case for passing matching Element as context to onMatch traversal?
And what about delegating this « business stuff » to an event strategy ?
So long as
mergeE
is used as a start step, I think you can make this work. But it maybe that this ability needs to get disabled temporarily in order to prevent some error conditions we have seen lately from happening as @Valentyn Kahamlyk mentions while we rework the mergeE
semantics a little. I'll post an example in a bit. Need to type one up.Solution
and then
@spmallette has been working on some PRs to improve a few
mergeE
behaviors. I would like him to comment on whether my example will still be vallid after those updates land.
So @rpuga that is one way you can (with the current latest version) make this work. Regarding EventStrategy @Flynnt , those only really make sense when the graph is embedded into the application (as a TinkerGraph can be). In order to catch database wide changes you need something more like the Amazon Neptune CDC stream, or JanusGraph triggers.Totally agree. And with those, transactional problems can occurs.
I think that the best approche for the use case is a change in the data models. And not in using the merge step. with the introduction of a vertex « phone calls » and « call » (for exemple) phone calls beeing liked to the two person and liked to each call. This way a new call is just a new vertex in the graph liked to a relation. And for knowing the count, you can just count the edges.
Thanks @Kelvin Lawrence, your solution works great!
Adapting it to the example graph I was using, it looks like this:
FYI @spmallette and @Valentyn Kahamlyk this is I think one of the key cases where being able to do additional work inside
onMatch
is very useful.Will we have same behavior for starting and mid-traversal
mergeE
?Currently no unfortunately. It will depend on what is in the stream until changes can be made to the way the step is working today. I called out this case mainly as an example of a behavior that needs to be supported in some way (as it is very useful).