Article DetailsDetailsHelp Details When seeking to compare two graphs (or sub-graphs) to determine if they are equivalent, the following Cypher statements will produce a md5sum of the nodes and properties to make that comparison. For example, you may wish to compare data between a test/QA instance with that on a production instance. MATCH (n:Movie) WITH n ORDER BY n.title WITH collect(properties(n)) AS propresult RETURN apoc.util.md5(propresult); Note that the above Cypher requires the installation of the apoc stored procedures set. When executed against the default "Movies" Graph data set, which includes 38 nodes labelled "Movie", this returns: md5_property 3f8d4737d078783e12f7cf57a207dd67 The above example query, examines all nodes with the label :Movie, whilst producing a md5sum of all properties of those nodes and using that sum to produce a md5sum hash. To get correct results, it is necessary to order the nodes by a property value defined for each node and unique. For this reason, one might want to use a property defined as a property existence constraint and unique property constraint. For example if the :Movie nodes had multiple nodes with the same title property, and since the Cypher above is ordering by n.title, then the results are passed to the md5 stored procedure in the order they are found. This is typically based on the order in which the nodes were created. If there were two :Movie nodes with title='The Matrix' created with the following Cypher: CREATE (n:Movie {title:'The Matrix', genre:'Sci-Fi'}) CREATE (n1:Movie {title:'The Matrix', genre:'Action'}) Subsequently executing the Cypher to produce the md5 hash, will produce a md5_property as: md5_property 5bc18a680ef59ba09466da4217166d30 However, if the order of CREATE statements was reversed, as: CREATE (n1:Movie {title:'The Matrix', genre:'Action'}) CREATE (n:Movie {title:'The Matrix', genre:'Sci-Fi'}) the result of the same md5 hashing Cypher will yield a different md5_property: md5_property c3c565b45457d2182731050e0cbab221 In the above example, so as to get the correct md5 values, regardless of the order of the CREATE statement, one needs to execute Cypher, which will return data in a guaranteed order, using an ORDER BY clause: MATCH (n:Movie) WITH n ORDER BY n.name, n.genre WITH collect(properties(n)) AS propresult CALL apoc.util.md5(propresult) YIELD value AS md5_property RETURN md5_property which will always return: md5_property c3c565b45457d2182731050e0cbab221 NOTE: We cannot simply collect(n) (i.e. the entire node) as it includes the internal node id (a unique internal identifier). If the same Cypher statement is executed on two separate environments, yet, yield the same md5 sums, the nodes can be proven to be the same in terms of the definition of labels and properties. InformationTitleHow do I compare two graphs for equalityArticle Created Date3/15/2024, 10:57 PMURL Name360037560013-How-do-I-compare-two-graphs-for-equalityLast Modified Date5/22/2024, 5:07 AM