Merge vertices to combine properties using group()

260 views
Skip to first unread message

bama...@gmail.com

unread,
Jun 18, 2021, 10:34:34 AM6/18/21
to Gremlin-users
I'm doing something similar to this post:  titan - Gremlin - how do you merge vertices to combine their properties without listing the properties explicitly? - Stack Overflow

My use case is pretty simple. The graph looks like this: v1 ---hasChange--> v2 ---hasChange---> v3. 

My query looks like this: 

g.V('v1').aggregate('A').
until(__.not(out('hasChange'))).
repeat(out('hasChange').aggregate('A)).
cap('A').
unfold().
valueMap().
unfold().
group().
by(select(keys)).
by(select(values))

If v1 has 'name': 'Mike' and v3 has 'name': 'Jane', then the query above returns 'Jane' for the 'name', which is what I want. 

However, from the post linked above, there is this comment: "Note, that there are two name properties and in theory you won't be able to predict which name makes it into your merged result..."

What does this mean? I'm hoping it doesn't mean that sometimes 'Mike' would be returned as the value in the 'name' property. If it does mean that, under what circumstances might this happen, and how can I avoid it? 

Thanks!

Stephen Mallette

unread,
Jun 21, 2021, 7:14:27 AM6/21/21
to gremli...@googlegroups.com
In the case of that question, I think the "Note" was meant to draw attention to the fact that Gremlin doesn't enforce order so, depending on the underlying graph, out('created') could have returned "name" in any particular order...for that matter, and perhaps to go further custom implementations of union(identity(), out("created")) could have the potential to alter the order (though the default should exhaust each child traversal in the order it is supplied). So, in that sense, unless you knew something about your graph you wouldn't know for sure how that merge would take place.

In your case, your graph structure seems to be such that you don't really have this problem. Results are aggregated to "A" and their insertion order should be preserved in that side-effect when they are unfolded after the cap("A").

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/6c9d722f-239d-4639-959a-d7e0be7484d7n%40googlegroups.com.

bama...@gmail.com

unread,
Jun 21, 2021, 8:19:07 AM6/21/21
to Gremlin-users
Ah, okay - that answers my questions. Good to know, and I really appreciate the help. 
Reply all
Reply to author
Forward
0 new messages