Question

I want to look for a vertex, get an edge 'views', remove it, and replace with a new edge between the same vertices.

g.V('uuid','bf4dcbd24e9944319954dec5ad60c658')  
.inE('views')
.sideEffect{g.addEdge(it.outV.next(),it.inV.next(),'likes')}
.sideEffect{g.removeEdge(it)}

This works, but is it the best way? Renaming the edge is an option?

Was it helpful?

Solution

You can use sideEffect as you did. That approach has the positive aspect of being straightforward and easy to understand. However, my personal preference for "production" Gremlin code is to use explicit Gremlin functions when they are available. In this case, I see the opportunity to use "link" and "step closures" (https://github.com/tinkerpop/gremlin/wiki/Step-Closures):

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.E
==>e[10][4-created->5]
==>e[7][1-knows->2]
==>e[9][1-created->3]
==>e[8][1-knows->4]
==>e[11][4-created->3]
==>e[12][6-created->3]
gremlin> g.v(1).as('x').outE('knows').as('toRemove').inV.except('x').linkIn('swonk','x').sideEffect{v,m->g.removeEdge(m.toRemove)} 
==>v[2]
==>v[4]
gremlin> g.E
==>e[1][1-swonk->4]
==>e[10][4-created->5]
==>e[0][1-swonk->2]
==>e[9][1-created->3]
==>e[11][4-created->3]
==>e[12][6-created->3]

In the above I "rename" all the "knows" edges for g.v(1) to "swonk".

OTHER TIPS

fixed the first error before queston eddit.


Done...

g.V('uuid','bf4dcbd24e9944319954dec5ad60c658') 
.inE('views')
.sideEffect{g.addEdge(it.outV.next(),it.inV.next(),'likes')}

the .next() fixed the script..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top