2

If we have 2 graph databases 'A' and 'B' and currently there is no relationship between nodes A graph database and B graph database, and now I have to add a relationship between a node of A and a node of B then how woud I do that using AGE. E.g A can be an employees Graph Database, and B can be any car dealers Graph Database, and now I want to add the relationship that which member wants which car, how would I do that using Apache AGE.

JoshInnis
  • 108
  • 6

3 Answers3

2

There is not way to create a relationship between two nodes in separate graphs. You can write some SQL to create a crosswalk table between two nodes in other graphs, but if you want to create an edge between two nodes, they need to be in the same graph.

JoshInnis
  • 108
  • 6
  • So, can I make a new graph and save the relationships in that graph? – Muhammad Zahid Jan 17 '23 at 08:01
  • You can make a new graph and import both those nodes into that graph and make a relationship. However the id, start_id and end_id that a vertex and edge have are only unique in a per graph level, and trying to link the two vertices together will cause data integrity issues. – JoshInnis Jan 17 '23 at 08:03
  • Well, I can make another graph, add the data I need as a Label e.g the name and the car an employee wants. Yeah thanks – Muhammad Zahid Jan 17 '23 at 08:42
0

You can not add a relationship between a node of A and a node of B which belong to different graphs, But apache-age provides you the facility to query Multiple Graphs, which you can use to achieve your goal to some extent.

There is no restriction to the number of graphs an SQL statement can query. Allowing users to query more than one graph at the same time.

SELECT graph_1.name, graph_1.age, graph_2.license_number
FROM cypher('graph_1', $$
    MATCH (v:Person)
    RETURN v.name, v.age
$$) as graph_1(col_1 agtype, col_2 agtype, col_3 agtype)
JOIN cypher('graph_2', $$
    MATCH (v:Doctor)
    RETURN v.name, v.license_number
$$) as graph_2(name agtype, license_number agtype)
ON graph_1.name = graph_2.name

Result:

enter image description here

Kamlesh Kumar
  • 351
  • 1
  • 7
0

A relationship between two nodes in different networks cannot be established. If you wish to establish an edge between two nodes, they must be in the same graph, however you can use some SQL to create a crosswalk table between two nodes in separate graphs.