Create Edges between Vertices with matching property contents #1464
-
Hello 😃 I'm trying to build a graph from XML data. The XML data is basically a tree structure, but it's using cross references through ID attributes. My idea was to import all elements as Vertices and use the Database to create the edges. Example Data after XML import:
There shall be edges between all vertices where I got the desired result with gremlin using this:
With couple of thousand of pairs this already takes almost an hour. Could you please help me to improve the performance? I'm pretty new to graph databases, so please bear with me. Is there something I can do on the schema side, like using indexes? At least with the specific query I used, having indexes on Any suggestions are welcome 😄 Greetings, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
I think the fastest way (without writing code) is using SQL. First, very important is creating an index on guid (so lookups are O(logN) ):
Let's say the vertices are stored by using the type "V". I don't know how you import the nodes. Are you creating all the vertices first and then attaching the relationship? This is a script that takes 2 parameters let $parent = select from V where guid = $parentGuid;
let $child = select from V where guid = $childGuid;
let e = create edge Part_Of from $chile to $parent;
return $e; I hope this helps and gives you some hints. |
Beta Was this translation helpful? Give feedback.
-
I'm creating the nodes through SQL statements using the HTTP/JSON API. After all the nodes are created I'm trying to create all relationships with a single query. What I'm trying to do as pseudo code:
That is what the gremlin query is doing. But it's pretty slow. I was hoping there is a "native" SQL query, which leverages indexes and performs better. Edit: I forgot to mention. The nodes can be of different types, representing the types from the XML input. |
Beta Was this translation helpful? Give feedback.
-
I had a look at SQL Scripting. I thought that would do the trick: let children = select from V where parent_id is not null;
foreach (child in $children){
let parents = select from V where guid = $child.parent_id;
foreach (parent in $parents) {
let e = create edge Part_Of from $child to $parent;
}
} But it fails with If I remove |
Beta Was this translation helpful? Give feedback.
I was able to reproduce it and found the issue: $parent is an actually reserved variable used to refer to the context's parent (if any). Contexts are linked in a tree for execution. Replace
parent
withp
and it will work.