1

I'm trying to upsert two vertices in a single query. I'm doing the following query, but the second vertex somehow iterates the entire graph (see image clipped from executeprofile).

What am I misunderstanding here?

g
  .V('1')
  .fold()
  .coalesce(
    unfold(),
    addV('Company').property('id', '1').property('pk','1')
  )
  .aggregate('a')
  .V('2')
  .fold()
  .coalesce(
    unfold(), 
    addV('Person').property('id', '2').property('pk', '2')
  )
  .as('b')

Wholegraph iterated

Shay Nehmad
  • 1,103
  • 1
  • 12
  • 25
bech
  • 627
  • 5
  • 22
  • I'm unsure, but why are you using aggregate('a') and not .as('a') there? Perhaps aggregate after coalesce behaves funny https://tinkerpop.apache.org/docs/current/reference/#store-step – Shay Nehmad Feb 09 '21 at 20:36
  • I've tried switching it to .as with no effect, but it's due to me removing stuff that is beyond the point, where I needed the aggregate (adding edges etc) – bech Feb 09 '21 at 20:38
  • Can you perhaps explicitly find V('1') and V('2') from anonymous traversals inside the coalesce calls, instead of folding and unfolding? – Shay Nehmad Feb 09 '21 at 20:40
  • I just tried replacing unfold with __.V('1') and __.V('2') to no avail. Also tried with and without the fold step. I'm pretty new to gremlin so I'm probably misunderstanding something basic. – bech Feb 09 '21 at 20:46
  • Is [this](https://medium.com/@jayanta.mondal/cosmos-db-graph-gremlin-api-how-to-executing-multiple-writes-as-a-unit-via-a-single-gremlin-2ce82d8bf365) similar to your situation? – Tiny Wang Feb 10 '21 at 09:37

1 Answers1

0

Eventually, I managed to figure out the solution, albeit not the reason.

I converted to (roughly) this:

g
  .V('1')
  .fold()
  .coalesce(
    g.V('1'),
    addV('Company').property('id', '1').property('pk','1')
  )
  .aggregate('a')
  .coalesce(
    g.V('2'), 
    addV('Person').property('id', '2').property('pk', '2')
  )
  .as('b')

So basically removing the second .V('2') and instead putting it inside the coalesce. I guess there must be some way to remove the very first V('1'), but I haven't quite figured that out yet.

bech
  • 627
  • 5
  • 22