Reputation: 900
I have a problem running this Gremlin query in Azure CosmosDB.
g.V().
has('node', 'id', 'new').
fold().coalesce(
unfold(),
addV('node').
property('id', 'new').
property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
).V().
has('node', 'id', 'new').
as('new').
V().
has('node', 'id', 'root').
coalesce(
outE('contains').where(inV().as('new')),
addE('contains').to('new')
).V().
has('node', 'id', 'new').
as('new').
V().has('userGroup', 'id', 'userGroup1').
coalesce(
outE('hasAccess').where(inV().as('new')),
addE('hasAccess').to('new')
)
I get two problems:
The base for the query is (images from gremlify.com):
g.addV('node').
property('id', 'root').
property('partitionKey', '33cb2571f8e348eaa875e6a2639af385')
g.addV('userGroup').
property('id', 'userGroup1').
property('partitionKey', '1')
and I want to end up like:
with a query that can be run multiple times without changing anything (idempotent). If I do this in separate queries it works fine:
g.V().
has('node', 'id', 'new').
fold().coalesce(
unfold(),
addV('node').
property('id', 'new').
property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
)
g.V().
has('node', 'id', 'new').
as('new').
V().
has('node', 'id', 'root').
coalesce(
outE('contains').where(inV().as('new')),
addE('contains').to('new')
)
g.V().
has('node', 'id', 'new').
as('new').
V().has('userGroup', 'id', 'userGroup1').
coalesce(
outE('hasAccess').where(inV().as('new')),
addE('hasAccess').to('new')
)
But I want to save two calls to the DB and do it in one go.
Upvotes: 2
Views: 260
Reputation: 2856
From my experience using the V()
step in the middle of a traversal is not well optimized in some vendors, even when followed by a strong filter like has('id', <name>)
, and I think you should try to avoid using it if you want to do a single query.
you can try:
g.V().hasLabel('node', 'userGroup').has('_id', within('new', 'root', 'userGroup1')).
fold().as('vertices').coalesce(
unfold().has('node', '_id', 'new'),
addV('node').property('_id', 'new').
property('partitionKey', 'edd1f6ca3b1c446987d7da29e370cc7e')
).as('new').
select('vertices').unfold().has('node', '_id', 'root').coalesce(
outE('contains').where(inV().as('new')),
addE('contains').to('new')
).
select('vertices').unfold().has('userGroup', '_id', 'userGroup1')
coalesce(
outE('hasAccess').where(inV().as('new')),
addE('hasAccess').to('new')
)
example: https://gremlify.com/pdtla2bsrc/1
Upvotes: 1