Neptune query behavior during edge creation

28 Views Asked by At

Gremlin query submitted to neptune to create edge , behaves differently when source/target vertices are missing.

we are using gremlin query in below format to submit edge creation on amazon neptune.

    g.V('unq://id1').as('from')
    .addE('id1\~core.DataFlow').from('from')
    .to(\_\_.V('unq://id2'))
    .property('prop1','abcd')
    .property('prop2','xyz')```


The above query fails only when the target vertex which is unq://id2 is missing. With the exception 'The traversal has tried to use a null or non-existent value in the step'
It doesn't fail when the source vertex is missing. It also doesn't fail, when both the source & target vertex are missing.

Is this behavior expected?

I wanted my queries to fail when either vertices are missing.
1

There are 1 best solutions below

0
Kelvin Lawrence On

If the source vertex does not exist, the way the query is written, it will just end as the first V will not have yielded a result.

so if we assume that 'unq://id1' does not exist, then the query will end after the g.V('unq://id1') part.

If you need to know that that vertex exists or otherwise fail you could use a coalesce step something like .fold().coalesce(unfold(),fail('source vertex does not exist')) after the initial g.V(...).

As an alternative you could explore using the fairly new mergeE step. That step will return an error if either the source or target, or both, are missing.