Warm tip: This article is reproduced from serverfault.com, please click

Is it possible to change edges between vertices in gremlin

发布于 2020-12-03 05:15:34

I have a scenario where I may need to update the from/to vertex of an already existing edge. I dont think there is any mechanism in gremlin to do so. So, what would be an ideal approach to achieve such functionality? What I can think of is -

  • Assuming To Vertex changes over time in an edge, Make sure the Edge ID is unique something like "From-Relationshipname"
  • While adding new edges check if Edge is already present then drop old Edge using the EdgeId and create a new one

Is it an efficient way?

Questioner
samairtimer
Viewed
0
Divij 2020-12-05 06:31:38

Check the following recipe published in Gremlin docs for moving an edge.

The "marko" vertex contains a "knows" edge to the "vadas" vertex. The following code shows how to "move" that edge to the "peter" vertex in a single traversal:

g.V().has('name','marko').as('a').
       outE('knows').as('e1').filter(inV().has('name','vadas')).
       V().has('name','peter').
       addE('knows').from('a').as('e2').
       sideEffect(select('e1').properties().
                  unfold().as('p').
                  select('e2').
                  property(select('p').key(), select('p').value())).
       select('e1').drop()

Source: https://tinkerpop.apache.org/docs/current/recipes/#edge-move