Created
October 14, 2016 00:50
-
-
Save Torenable/958e4f3e4d32443d9695e18d825865d8 to your computer and use it in GitHub Desktop.
Dedup relationships with identical properties in Cypher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (a) -[r]- (s) | |
// use two `WITH` clauses to build a sorted list | |
WITH r, a // a for group by | |
ORDER BY id(r) | |
WITH type(r) AS t, collect(r) AS coll, a | |
// identify duplications | |
WITH t, reduce(s = [], x IN coll| | |
CASE any(y IN coll WHERE id(x) > id(y) | |
AND y.KEY1 = x.KEY1 | |
AND y.KEY2 = x.KEY2) | |
WHEN true THEN s + x | |
ELSE s | |
END | |
) AS del, a | |
FOREACH(x IN del| DELETE x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment