databasegraphgremlinamazon-neptunetinkerpop3

How to use apache Gremlin constant in AWS Neptune database?


How to use apache gremlin constant in AWS Neptune database?

g.V().hasLabel('user').has('name', 'Thirumal1').coalesce(id(), constant("1"));

Not getting constant value in the output. The document says, need to use it with sack https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-step-support.html. How to use constant in AWS Neptune.


Solution

  • If the aim is to return a 1 if the vertex does not exist you need to use the fold().coalesce() pattern. As written in the question, the query will end before the coalesce if the has returns no results.

    You could do something like this

    g.V().hasLabel('user').
          has('name', 'Thirumal1').
          fold().
          coalesce(unfold().id(), constant("1"))
    

    In TinkerPop 3.6 a new mergeV step was added. Once database providers move up to that version, you will be able to use mergeV coupled with onCreate and onMatch.

    UPDATED 2023-03-17

    In TinkerPop release 3.6.0 two new steps mergeV and mergeE were added to Gremlin. These are designed to make the "create if not exist" or "upsert" type queries much easier to write. In most cases these new steps will replace the former fold...coalesce pattern. As of version 1.2.1.0 Amazon Neptune now supports the required TinkerPop version. For further reading please checkout the TinkerPop documentation