Adding multiple edges with info

178 views
Skip to first unread message

Max Murmann

unread,
Apr 8, 2021, 7:14:03 AM4/8/21
to Gremlin-users
Hey guys

I'm trying to add edges between a list of pairs of nodes (with a property on the edge), without having to loop through and do each one individually. The nodes all already exist in the graph so no need to add the nodes

I'm using gremlin-python on an AWS neptune instance.

Currently I've got a list of dictionaries containing the information in the format:
{'v1':uuid,'v2':uuid,'score':int}

Is there a way to do this in one query?

Thanks

Max

Kelvin Lawrence

unread,
Apr 9, 2021, 11:59:27 AM4/9/21
to Gremlin-users
Hi Max - This is probably a good candidate for a query where the edge information is injected at the start of the query as a map. There are some examples in the Gremlin recipes here:


Cheers,
Kelvin

Max Murmann

unread,
May 5, 2021, 5:13:52 AM5/5/21
to Gremlin-users
This worked great, thanks

Only issue is the insert is taking an extremely long time. I'm adding a lot of edges (10k+) and it's taking hours. Is there any way of speeding this up? Might be more to do with how Neptune is parallelising the queries. 

Any tips let me know!

Thanks

Max

Kelvin Lawrence

unread,
May 5, 2021, 12:06:43 PM5/5/21
to Gremlin-users
Adding 10K edges should take a few seconds at most using the map injection pattern. I do that quite often. Are you firing off lots of 10K batches in parallel? If so then the throughput will depend on the size of instance you are connected to. 

Max Murmann

unread,
May 6, 2021, 5:10:34 AM5/6/21
to Gremlin-users
The query I'm doing is 

my_list = [{'v1':uuid_1, 'v2':uuid_2, 'score':int}, {'v1':uuid_1, 'v2':uuid_2, 'score':int}, .....]

 g.inject(*my_list).as_('j').addE('label').from_(select('v1')).to(select('v2')).property('score',select('j')).iterate()

my_list is more like 100k edges having looked at it. 
   
This is being done in gremlin_python on an AWS Neptune instance.

When we ran it last time, it immediately hit 100% on our CPU (The instance is on a t5.2XL) 

Could you let me know what the issue might be?

Thanks

Max
Reply all
Reply to author
Forward
0 new messages