Venkata Dorisala
Venkata Dorisala

Reputation: 5075

Clone an Edge and target vertex in Cosmos Gremlin

g.AddV('test').property('id','1').property('name','test 1')
g.AddV('test').property('id','2').property('name','test 2')

g.V('1').AddE('owns').to(g.AddV('another').property('id','3'))

Is there any way i can clone this owns edge and it's target another vertex of test 1 with all properties into test 2 vertex? This is just a sample data. I have vertex with at least 10 properties.

NOTE : Query needs to support cosmos db gremlin api.

Upvotes: 0

Views: 793

Answers (2)

stephen mallette
stephen mallette

Reputation: 46226

The answer to this one is mostly presented in this other StackOverflow question which explains how to clone a vertex and all it's edges. Since this question is slightly different I thought I'd adapt it a bit rather this suggesting closing this as a duplicate.

gremlin> g.V().has('test','name','test 1').as('t1').
......1>   outE('owns').as('e').inV().as('source').
......2>   V().has('test','name','test 2').as('target').
......3>   sideEffect(       
......4>     select('source').properties().as('p').
......5>     select('target').
......6>       property(select('p').key(), select('p').value())).
......7>   sideEffect(
......8>     select('t1').
......9>     addE(select('e').label()).as('eclone').
.....10>       to(select('target')).
.....11>     select('e').properties().as('p').                        
.....12>     select('eclone').
.....13>       property(select('p').key(), select('p').value()))
==>v[3]
gremlin> g.E()
==>e[8][0-owns->6]
==>e[10][0-owns->3]
gremlin> g.V().valueMap(true)
==>[id:0,label:test,name:[test 1],id:[1]]
==>[id:3,label:test,name:[test 2],id:[3]]
==>[id:6,label:another,id:[3]]

Note that since labels are immutable, you are stuck with the vertex label being "another" given the way that you laid out your sample data. Also, I know it is just sample data, but note that overloading "id" isn't a good choice as it can lead to confusion with T.id.

Upvotes: 2

Jay Gong
Jay Gong

Reputation: 23792

Execute api: g.V().has('name','test 1').id()

enter image description here

Then try to loop the results in java code and execute the add edge api:

g.V(<the id of vertex loop>).AddE('owns').to(<the id of vertex 'test2'>)

If the vertexes of test 2 are multiple,then you could two-dimensional loop.

Upvotes: 0

Related Questions