Is it possible to tell whether a Gremlin Drop() step did anything?

不问归期 提交于 2019-12-13 03:47:43

问题


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()

回答1:


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.



来源:https://stackoverflow.com/questions/57465113/is-it-possible-to-tell-whether-a-gremlin-drop-step-did-anything

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!