Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
krlawrence opened this issue Mar 9, 2020 · 1 comment
Closed

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

krlawrence opened this issue Mar 9, 2020 · 1 comment

Comments

@krlawrence
Copy link
Owner

krlawrence commented Mar 9, 2020

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
Copy link
Owner Author

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

@github-project-automation github-project-automation bot moved this to Medium Priority in Planning Aug 29, 2024
@github-project-automation github-project-automation bot moved this from Medium Priority to Complete in Planning Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Complete
Development

No branches or pull requests

2 participants