How can I find out if a vertex was dropped in Gremlin?

0

I want to try to remove a vertex and I want to know if I deleted something. If I do

g.V().has('name', 'deleteme').drop()

then there's no way for me to know if there was a vertex to begin with. I always get an empty result. Is there a way to tell?

I figured I could tag the deleted data and then select it

g.V().has('name', 'deleteme').as('deleted').drop().select('deleted')

but this gives me an error

Failed to execute query: g.V().has('name', 'deleteme').as('deleted').drop().select('deleted'): Script eval error: ActivityId : 959af7a4-b955-4127-be46-2dc160dd4ece ExceptionType : GraphCompileException ExceptionMessage : Gremlin Query Compilation Error: Column reference R_0["_value"] cannot be located in the raw records in the current execution pipeline. Source : Microsoft.Azure.Graphs GremlinRequestId : 959af7a4-b955-4127-be46-2dc160dd4ece Context : graphcompute Scope : graphstg-phyplan GraphInterOpStatusCode : QuerySyntaxError HResult : 0x80131500

Is there a recommended way to achieve this?

(I'm using the C# SDK for the Azure CosmosDB if that makes a difference)

gremlin
asked on Stack Overflow Feb 12, 2019 by The Hoff

1 Answer

2

The drop() step is effectively both a side-effect and a filter step. It's a side-effect in that it mutates the databases and a side-effect because it simply kills whatever traversers are in the stream. Short of an exception being thrown it tends to be safe to assume that the data was removed (if it existed in the first place - but perhaps that's what you want to know).

Using the modern toy graph as an example, I think the easiest way to do this is with the sideEffect() step which effectively forces drop() to behave only as a side-effect:

gremlin> g.V().has('person','name','marko').sideEffect(drop()).constant('gone')
==>gone
gremlin> g.V().has('person','name','marko').sideEffect(drop()).constant('gone')
gremlin>

but I'm not so sure CosmosDB supports that step yet. I suppose that you could do this which is less intuitive and readable but seems to accomplish the same thing:

gremlin> g.V().has('person','name','marko').union(constant('gone'),drop())
==>gone
gremlin> g.V().has('person','name','marko').union(constant('gone'),drop())
gremlin>
answered on Stack Overflow Feb 12, 2019 by stephen mallette

User contributions licensed under CC BY-SA 3.0