graph icon indicating copy to clipboard operation
graph copied to clipboard

Add examples of seeding addV() and addE() with maps

Open krlawrence opened this issue 5 years ago • 1 comments

Add examples of using K,V pairs to see a traversal that will create vertices and or edges along the lines of:

nodes = [
    ["name": "Kim",    "breed": "Beagle"],
    ["name": "Max",    "breed": "Mixed"],
    ["name": "Toby",   "breed": "Golden Retriever"]]    

gremlin> g.inject(nodes).unfold().as("nodes").
......1>   addV("dog").as("new_node").
......2>   sideEffect(select('nodes').unfold().as('kv').
......3>              select('new_node').
......4>              property( select('kv').by(Column.keys),
......5>                        select('kv').by(Column.values))).
......6>          id().toList()    
==>9
==>12
==>15               

gremlin> g.V().valueMap().with(WithOptions.tokens)
==>[id:9,label:dog,name:[Kim],breed:[Beagle]]
==>[id:12,label:dog,name:[Max],breed:[Mixed]]
==>[id:15,label:dog,name:[Toby],breed:[Golden Retriever]]  


g.inject(['age':28,'name':'Bob']).as('data').
   addV('Person').as('new').
   select('data').unfold().as('props').
   select('new').
   property(select('props').select(keys),select('props').select(values)) 

Also an example of adding edges given a set of IDs

gremlin> g.inject([[a:1,b:2],[a:5,b:6]]).
......1>   unfold().as('p').
......2>   addE('test').
......3>     from(V().as('v').where(eq('v')).by(select('p').select('a')).by(id)).
......4>     to(V().as('v').where(eq('v')).by(select('p').select('b')).by(id))   
==>e[61286][1-test->2]
==>e[61287][5-test->6]  

Should also show how to use coalesce to create a merge pattern such as:

gremlin> g.inject([['code':'AUS'],['code':'XYZ'],['code':'SFO']]).
......1>   unfold().as('data').
......2>   coalesce(V().hasLabel('airport').
......3>     where(eq('data')).
......4>       by('code').
......5>       by(select('code')),
......6>     addV('airport').
......7>       property('code',select('code')))
==>v[3]
==>v[61286]
==>v[23]    

krlawrence avatar Mar 09 '20 21:03 krlawrence

The work to resolve this issue should probably positioned to new coverage of mergeV and mergeE once created.

krlawrence avatar Sep 23 '23 19:09 krlawrence