Apache AGE- How to Implement relationship between 2 graphs

360 Views Asked by At

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.

2

There are 2 best solutions below

3
On BEST ANSWER

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.

1
On

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