0

I have a traversal that ends with a drop() to delete a vertex. I would like to be able to tell the difference between the drop() removing a vertex and the traversal just not matching anything.

I tried adding an alias to one of the earlier nodes and select()ing it at the end of the traversal, but that doesn't return anything even when the traversal does match the graph.

e.g.

g.V('id', '1').as('flag')
.out('has_child')
.drop()
.select('flag')
.toList()
Dan
  • 7,446
  • 6
  • 32
  • 46

1 Answers1

4

The trick is that drop() is a filter step so it removes objects from the traversal stream. You can work around that situation a bit by dropping by sideEffect():

gremlin> g.V().has('person','name','marko')
==>v[1]
gremlin> g.V().has('person','name','marko').sideEffect(drop())
==>v[1]
gremlin> g.V().has('person','name','marko')
gremlin>

The return of the vertex would mean that it was present and dropped, but if no value is returned then it wasn't present in the first place to be dropped.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • It appears that at least with the Python Gremlin implementation I'm using if you try to return the dropped vertex you get an error. However, returning something earlier in the traversal (as in the question) does work. `g.V('id', '1').as('flag').out('has_child').sideEffect(drop()).select('flag').next()` – Dan Aug 13 '19 at 09:21
  • what was the error? and what gremlinpython version? – stephen mallette Aug 13 '19 at 10:50
  • Not sure what version, I've set up the tutorial AWS/Neptune/SageMaker notebook – Dan Aug 13 '19 at 10:57
  • `GremlinServerError: 597: {"requestId":"d34ba2c9-de1e-4a8d-94da-b6c2ffb58925","code":"ConstraintViolationException","detailedMessage":"Unable to find label associated with the vertexId a4b64522-9cda-1b34-8f76-634242933a0d"}` The vertex ID is the vertex that I'm trying to drop – Dan Aug 13 '19 at 11:04
  • i'm thinking that neptune has slightly different graph element detachment semantics than most graphs. even as a sideeffect `drop()` must "kill" that vertex somehow and prevent the result from being serialized back. your solution works, but it's good form to avoid step labels if possible - what happens if you use my approach but add `constant('dropped')` to the end? does that work? – stephen mallette Aug 13 '19 at 11:58
  • Thanks, yes putting `constant('dropped)` on the end appears to work. – Dan Aug 13 '19 at 13:13