gremlin - How to remove an edge and add a new edge between two vertices? -


i'm trying drop edge , add new edge between 2 vertices. how do in tinkerpop3?

def user = g.v().has("userid", 'iamuser42').has("tenantid", 'testtenant').haslabel('user');  user.oute("is_invited_to_join").where(otherv().has("groupid", 'test123')).drop(); def group = g.v().has("groupid", 'test123').has("tenantid", 'testtenant').haslabel('group').next(); user.addedge("is_member_of", group); 

this error on gremlin shell:

no signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.defaultgraphtraversal.addedge() applicable argument types: (java.lang.string, com.thinkaurelius.titan.graphdb.vertices.cachevertex) values: [is_member_of, v[8224]] 

thank you.

the gremlin console tutorial discusses issue bit. not iterating traversal. consider following:

gremlin> graph = tinkerfactory.createmodern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph.traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> person = g.v().has('name','marko') ==>v[1] 

great! person vertex stored in "person" variable...or it?

gremlin> person.class ==>class org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.defaultgraphtraversal 

apparently not vertex. "person" traversal, console sees such , iterates why "v1" in output. note traversal "done":

gremlin> person.hasnext() ==>false 

you need iterate traversal variable - in case, using next():

gremlin> person = g.v().has('name','marko').next() ==>v[1] gremlin> person.class ==>class org.apache.tinkerpop.gremlin.tinkergraph.structure.tinkervertex 

note have further problems down line in script because using vertex traversal, line:

user.oute("is_invited_to_join").where(otherv().has("groupid", 'test123')).drop(); 

will fail similar error because vertex not have oute(). need like:

g.v(user).oute("is_invited_to_join").where(otherv().has("groupid", 'test123')).drop(); 

if add edge , drop old 1 in same traversal, this:

gremlin> graph = tinkerfactory.createmodern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph.traversal() ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.v(1).oute('knows') ==>e[7][1-knows->2] ==>e[8][1-knows->4] gremlin> g.v(1).as('a').oute().as('edge').inv().hasid(2).as('b').adde('knew').from('a').to('b').select('edge').drop() gremlin> g.v(1).oute('knew') ==>e[12][1-knew->2] gremlin> g.v(1).oute('knows') ==>e[8][1-knows->4] 

arguably, might not readable breaking 2 or more separate traversals, can done.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -