Does gremlin provide the ability to clone a vertex for instance
v1->v2, v1->v3, v1->v4
how can I simply and efficiently create a new vertex v5
that also has edges that point to v2, v3, v4
(the same places that v1's
edges point to) without have to explicitly set them and instead saying something like g.createV(v1).clone(v2)
.
Note that I am using the AWS Neptune version of gremlin, solution must be compatible with that.
A
clone
step doesn't exist (yet), but it can be solved with a single query.Let's start with some sample data:
Now the query to clone the vertex might look a bit scary at a first glance, but it's really just the same pattern over and over again - jumping between the original and the clone to copy the properties:
And in action it looks like this:
UPDATE
Paging support is a little tricky. Let me split this whole thing into a 3-step process. I will use edge ids as the sort criterion and to identify the last processed edge (this might not work in Neptune, but you can use a unique sortable property instead).
I don't know if Neptune allows you to execute full scripts - if not, you'll need to execute the outer while loops in you application's code.