0
votes

My context:

  • gremlin-python
  • 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? 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.

For instance:

vertex ids to delete:

'vertex1', 'vertex2', 'vertex3'

edge ids to delete:

'edge1', 'edge2', 'edge3'

An example of the python function to chain on to g would be like:

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.

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!

1

1 Answers

4
votes

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.
  2. drop() is kills all traversers so the mid-traversal V() following it won't ever get executed.

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.