This repository was archived by the owner on Jan 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Add refactor.mergeNodes procedure
#623
Merged
Merged
Changes from 6 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f8eb271
Add merge nodes procedure
Josipmrden 6912496
Refactor tests for base level
Josipmrden 9cb40b0
Add test with .*
Josipmrden 34f0a29
Add more tests
Josipmrden da4ea92
Rename tests
Josipmrden 9da869e
Merge branch 'main' into refactor-merge-nodes
Josipmrden 56c5581
Address PR comments
Josipmrden cddc074
Add const
Josipmrden e1d5042
IIFE
Josipmrden 0a33364
Address PR comments
Josipmrden 95b8a24
Handle additional condition in IIFE
Josipmrden 6b4acb5
Merge branch 'main' into refactor-merge-nodes
Josipmrden 72a582d
Add move to label
Josipmrden 8c04a89
Merge branch 'main' into refactor-merge-nodes
Josipmrden 304d748
Refactor
Josipmrden cdeac48
Refactor
Josipmrden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}) CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'}) CREATE (n1)-[:KNOWS {since: 2020}]->(n2) CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3) CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| query: > | ||
| MATCH (n1:Person {age: 30}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'}) | ||
| CALL refactor.merge_nodes([n1, n2, n3], {`.*`: 'combine', mergeRels: true}) YIELD node | ||
| RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree; | ||
| output: | ||
| - name: [Bob, Charlie] | ||
| out_degree: 3 | ||
| in_degree: 3 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}) | ||
| CALL refactor.merge_nodes([n1, n2], {properties: 'COMBINE'}) YIELD node | ||
| RETURN node.name as name, node.age as age, node.city as city, node.country as country; | ||
| output: | ||
| - name: [Alice, Bob] | ||
| age: [30, 25] | ||
| city: New York | ||
| country: USA |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}) | ||
| CALL refactor.merge_nodes([n1, n2], {properties: 'combine'}) YIELD node | ||
| RETURN node.name as name, node.age as age, node.city as city, node.country as country; | ||
| output: | ||
| - name: [Alice, Bob] | ||
| age: [30, 25] | ||
| city: New York | ||
| country: USA |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n4:Employee {name: 'David', salary: 50000}) CREATE (n5:Manager {name: 'Eve', department: 'IT'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n4:Employee {name: 'David'}), (n5:Manager {name: 'Eve'}) | ||
| CALL refactor.merge_nodes([n4, n5], {properties: 'combine'}) YIELD node | ||
| RETURN node.name as name, node.salary as salary, node.department as department, labels(node) as labels; | ||
| output: | ||
| - name: [David, Eve] | ||
| salary: 50000 | ||
| department: IT | ||
| labels: [Employee, Manager] |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}) CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'}) CREATE (n1)-[:KNOWS {since: 2020}]->(n2) CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3) CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| query: > | ||
| MATCH (n1:Person {age: 30}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'}) | ||
| CALL refactor.merge_nodes([n1, n2, n3], {properties: 'combine', mergeRels: true}) YIELD node | ||
| RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree; | ||
| output: | ||
| - name: [Bob, Charlie] | ||
| out_degree: 3 | ||
| in_degree: 3 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}) | ||
| CALL refactor.merge_nodes([n1, n2], {properties: 'discard'}) YIELD node | ||
| RETURN node.name as name, node.age as age, node.city as city, node.country as country; | ||
| output: | ||
| - name: Alice | ||
| age: 30 | ||
| city: New York | ||
| country: null |
Empty file.
5 changes: 5 additions & 0 deletions
5
e2e/refactor_test/test_merge_nodes_invalid_empty_nodes/test.yml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| query: > | ||
| CALL refactor.merge_nodes([], {properties: 'combine'}) YIELD node | ||
| RETURN node; | ||
| exception: >- | ||
| "The nodes list cannot be empty" |
1 change: 1 addition & 0 deletions
1
e2e/refactor_test/test_merge_nodes_invalid_merge_rels_value/input.cyp
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}) CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'}) CREATE (n1)-[:KNOWS {since: 2020}]->(n2) CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3) CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1); |
7 changes: 7 additions & 0 deletions
7
e2e/refactor_test/test_merge_nodes_invalid_merge_rels_value/test.yml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| query: > | ||
| MATCH (n1:Person {age: 30}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'}) | ||
| CALL refactor.merge_nodes([n1, n2, n3], {`.*`: 'combine', mergeRels: "nothing"}) YIELD node | ||
| RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree; | ||
| exception: > | ||
| mergeRels parameter must either be true or false | ||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}) CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'}) CREATE (n1)-[:KNOWS {since: 2020}]->(n2) CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3) CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| query: > | ||
| MATCH (n1:Person {age: 30}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'}) | ||
| CALL refactor.merge_nodes([n1, n2, n3], {`.*`: 'combine', mergeRels: false}) YIELD node | ||
| RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree; | ||
| output: | ||
| - name: [Bob, Charlie] | ||
| out_degree: 0 | ||
| in_degree: 0 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}) CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'}) CREATE (n1)-[:KNOWS {since: 2020}]->(n2) CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3) CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'}) | ||
| CALL refactor.merge_nodes([n1, n2, n3], {properties: 'combine', mergeRels: true}) YIELD node | ||
| RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree; | ||
| output: | ||
| - name: [Alice, Bob, Charlie] | ||
| out_degree: 3 | ||
| in_degree: 3 |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}) | ||
| CALL refactor.merge_nodes([n1, n2], {properties: 'override'}) YIELD node | ||
| RETURN node.name as name, node.age as age, node.city as city, node.country as country; | ||
| output: | ||
| - name: Bob | ||
| age: 25 | ||
| city: New York | ||
| country: USA |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'}) CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'}); |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| query: > | ||
| MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}) | ||
| CALL refactor.merge_nodes([n1, n2], {properties: 'overwrite'}) YIELD node | ||
| RETURN node.name as name, node.age as age, node.city as city, node.country as country; | ||
| output: | ||
| - name: Bob | ||
| age: 25 | ||
| city: New York | ||
| country: USA |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.