Trouble understanding how to handle long queries with stores

39 views
Skip to first unread message

Edoardo Barp

unread,
Jul 10, 2021, 7:25:19 AM7/10/21
to Gremlin-users

I'm having issues understanding how to handle the stored objects when doing long queries.
Consider the following toy example:

g.addV("foo").property("a", "1").
addV("foo").property("a", "2").
addV("bar").property("a", "1").
addV("bar").property("a", "2")
.iterate()

Now, I want to connect the foo and bar vertices if they share the same value for a, pretty simple:

g.V().hasLabel("foo").as_("foo")
.V().hasLabel("bar").as_("bar")
.where("foo", eq("bar")).by("a")
.addE("is").from_("foo").to("bar")

However, in the case of a long query in which the selection step is not as straightforward, you will likely need to store instead of using `as` (any reducing barrier step would remove them). Then one might think we can simply do this:

g.V().hasLabel("foo").store("foo")
.V().hasLabel("bar").as_("bar")
.where("foo", eq("bar")).by("a")
.addE("is").from_("foo").to("bar")

But it's not the case because store is a bit peculiar. I don't exactly understand it, but it seems like it saves the selection as a folded collection. Then one might try to unfold first, but then chaos occurs. I have tried several alternatives, but can't seem to get it right. For example:

g.V().hasLabel("foo").store("foo")
.V().hasLabel("bar").as_("bar")
.sideEffect(select("foo").unfold().as_("foo"))
.where("foo", eq("bar")).by("a")
.addE("is").from_(select("foo").unfold()).to("bar")

returns
he by("a") modulator can only be applied to a traverser that is an Element or a Map - it is being applied to a BulkSet class instead.

I would highly appreciate any help understanding this!
Best,
Ed

HadoopMarc

unread,
Jul 25, 2021, 4:32:29 AM7/25/21
to Gremlin-users
Hi Ed,

Almost there:

g.V().hasLabel("foo").aggregate("foo").
    V().hasLabel("bar").as("bar").
    select("foo").unfold().as("foo2").
    where("foo2", eq("bar")).by("a").
    addE("is").from("foo2").to("bar")

Best wishes,    Marc

Op zaterdag 10 juli 2021 om 13:25:19 UTC+2 schreef barp.e...@gmail.com:
Reply all
Reply to author
Forward
0 new messages