Adding multiple vertices with coalesce

361 views
Skip to first unread message

Lilly

unread,
Aug 29, 2019, 5:39:10 AM8/29/19
to Gremlin-users
Hi everyone,

I was trying to do the coalesce trick, to add vertices only if they do not exist so far and then reusing them later on.
My minimal working example can be found on the bottom.
If I run this I get the error: java.lang.IllegalArgumentException: The provided traverser does not map to a value: v[4312]->[SelectOneStep(last,v1)].
Since it works fine with only a single vertex e.g. v1 and then adding a loop edge,
this suggests to me, that on "restarting" with another use of a graph traversal source V(), the previously stored values, i.e. v1 in this case, get lost.
However, in the Recipes http://tinkerpop.apache.org/docs/current/recipes/#element-existence precisely this is done and seems to work fine.

Am I missing something here?

Thanks for any suggestions!!


g.V().has("prefix", "ACT").fold().
coalesce(__.unfold(),
__.addV("prefix_node").property("prefix","ACT") ).as("v1").
V().has("prefix", "CTG").fold().
coalesce(__.unfold(),
__.addV("prefix_node").property("prefix","CTG")).as("v2").
addE("suffix_edge").from("v1").to("v2").iterate();

Lilly

unread,
Aug 29, 2019, 6:39:58 AM8/29/19
to Gremlin-users
Hi everyone,

I now understand the problem. The issue is, that the second call on fold() is a reducing barrier step, so it will destroy the previous traverser, such that v1 is no longer existent. This could in principle be solved with using aggregate instead of as for the first vertex.
However, I would like to reuse this label v1. Is there a way to clear it again, i.e. remove all elements stored in the list created via aggreagate("v1") after having used them for the addE step?

Thanks!

Robert Dale

unread,
Aug 29, 2019, 9:34:37 AM8/29/19
to gremli...@googlegroups.com
g.V().has("prefix", "ACT").fold().
coalesce(__.unfold(),
__.addV("prefix_node").property("prefix","ACT") ).as("v1").
        coalesce(__.V().has("prefix", "CTG"),

__.addV("prefix_node").property("prefix","CTG")).as("v2").
addE("suffix_edge").from("v1").to("v2").iterate();
Robert Dale


--
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/9aebb192-cf90-4368-9be4-eabf92056c9b%40googlegroups.com.

Lilly

unread,
Aug 29, 2019, 10:16:10 AM8/29/19
to Gremlin-users
Yes this now seems like the obvious solution. Thank you!
However, I do not see why the coalesce pattern uses this fold() stuff after all? Does this provide any advantages that I do not see?
To unsubscribe from this group and stop receiving emails from it, send an email to gremli...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages