neo4jproperty-graph

Can I define different attributes for the same values in two different nodes for the same label?


I would like to integrate data from two different relational databases into one labeled property graph. The databases have a different data structure for example:

System a:
First Name: Barack
Last Name: Obama

System b:
Name: Donald Trump

Defined Labels:
    :Person
    :SystemA
    :SystemB

Defined Nodes with Properties for the LabeledPropertyGraph:

:Person :SystemA
First Name: Barack
Last Name: Obama

:Person :SystemB
Name: Donald Trump

Is it possible to integrate data from two databases into to property graph like described?


Solution

  • Yes this is possible. Neo4j has no restrictions on what properties can be used between nodes, so nodes of the same label (:Person) can have completely different property keys from each other.

    You will of course want to reconcile this at some point in time so you can query the data in some common way.

    In the meantime you can use functions, such as coalesce(), to help you work with different data. For example, if you wanted to show the names of all :Person nodes and they were in these two different kinds of formats, you can query like:

    MATCH (p:Person)
    RETURN coalesce(p.Name, p.`First Name` + ' ' p.`Last Name`) as name
    

    The first non-null value encountered by the function will be used, so if a Name property exists it will be used, otherwise it will attempt to string concatenate the first and last name properties.