简体   繁体   English

gremlin-python在一次交易中删除多个顶点和边

[英]gremlin-python drop multiple vertices and edges in one transaction

My context: 我的情况:

  • gremlin-python gremlin-python
  • AWS Neptune AWS Neptune

My question is: 我的问题是:

1) Can I drop vertices and edges recursively in one transaction given that I have all the specific ids of the vertices and edges I want to drop? 1)考虑到我要删除的所有顶点和边的特定ID,我可以在一个事务中递归删除顶点和边吗? The aim is to write python function that evaluates each edge, and determine whether it needs to be dropped, and chain a gremlin query to drop it. 目的是编写评估每个边缘的python函数,确定是否需要删除它,并链接一个gremlin查询以删除它。

For instance: 例如:

vertex ids to delete: 要删除的顶点ID:

'vertex1', 'vertex2', 'vertex3'

edge ids to delete: 要删除的边缘ID:

'edge1', 'edge2', 'edge3'

An example of the python function to chain on to g would be like: 链接到g的python函数示例如下:

def chain_drop(g, vertex_id):
    g = g.V(vertex_id).drop()
    return g

The chained query i would like to execute as one transaction would ideally look something like: 我希望作为一个事务执行的链接查询理想情况下应类似于:

g.E('edge1').drop()
 .V('vertex1').drop()
 .E('edge3').drop()
 .V('vertex3').drop()
 .iterate() # execute all these queries as one transaction

The above doesn't work... And it seems I cannot .E('someid') in the middle of my gremlin query. 上面的方法不起作用...似乎在我的gremlin查询中间无法.E('someid')。

Slightly off topic but my best try (non-recursive) would be something like below: 稍微偏离主题,但我的最佳尝试(非递归)如下所示:

g.E('edge1', 'edge2', 'edge3').as_('edges')
 .V('vertex1', 'vertex2', 'vertex3').as_('vertices')
 .union(__.select('edges'),
        __.select('vertices'))
 .drop()
 .iterate()

Any help much appreciated! 任何帮助,不胜感激!

You can't do what you want to do exactly for two reasons: 您不能完全按照以下两个原因做您想做的事情:

  1. There is no mid-traversal E() as it is a start step only. 没有中间遍历E()因为它只是一个开始步骤。
  2. drop() is kills all traversers so the mid-traversal V() following it won't ever get executed. drop()将杀死所有遍历器,因此其后的中遍历V()将永远不会执行。

You can take a different approach however and simply gather all of your elements to remove and then then drop those...something like: 但是,您可以采用另一种方法,只需收集所有要删除的元素,然后删除这些元素即可,例如:

g.V(1).aggregate('x').V(2).aggregate('x').select('x').unfold().drop()

Note that dropping vertices will also drop edges so if those edges you want to drop are connected to the vertices you want to drop you don't need to drop them explicitly. 请注意,放下顶点也会放下边缘,因此,如果要放下的那些边已连接到要放下的顶点,则无需显式放下它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM