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.
CodePudding user response:
The coalesce() step returns the first option that returns a value. In your query example the id() step always returns a value so it will never return the constant("1"). The gremlin step support you refer to concerns pushdown of operations to the datastore. Fully down that page it is shown that really support is lacking for just a few gremlin steps.
CodePudding user response:
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
.