-
Notifications
You must be signed in to change notification settings - Fork 494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #600 - add a configuration option to mergeNodes that allows to …combine relationships of the same type and direction #850
Conversation
if (delete) source.delete(); | ||
PropertiesManager.mergeProperties(properties, target, conf); | ||
|
||
//check mergeRels parameter | ||
Object value = config.get("mergeRels") == null ? false : config.get("mergeRels"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is really weird, that info should come cleanly out of RefactorConfig please move it there and add a dedicated method
//check mergeRels parameter | ||
Object value = config.get("mergeRels") == null ? false : config.get("mergeRels"); | ||
if(value.equals(true)) { | ||
Map<String,Object> map = new HashMap<String, Object>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singletonMap
if (delete) source.delete(); | ||
PropertiesManager.mergeProperties(properties, target, conf); | ||
|
||
//check mergeRels parameter | ||
Object value = config.get("mergeRels") == null ? false : config.get("mergeRels"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOrDefault -> in refactorConfig
|
||
|
||
public void mergeRelsWithSameTypeAndDirectionInMergeNodes (Node node, RefactorConfig config, Direction dir){ | ||
List<Relationship> rels = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code is really weird, please fix it
use foreach
iterate over the iterator
node.getRelationships(dir).iterator().forEachRemaining(rels::add); | ||
for (int i = 0; i < rels.size()-1; i++) { | ||
for (int j = i + 1; j < rels.size(); j++) { | ||
if (rels.get(i).isType(rels.get(j).getType())){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't call rels.get() repeatedly, use local variables.
they should have the same start/end-node given that you iterate starting from that one
Map<String,Object> params = null; | ||
|
||
testCall(db, "MATCH (a1:ALabel {name:'a1'}), (a2:ALabel {name:'a2'}), (a3:ALabel {name:'a3'}), (a4:ALabel {name:'a4'}) " + | ||
" WITH head(collect([a1,a2,a3,a4])) as nodes CALL apoc.refactor.mergeNodes(nodes,{properties:\"combine\",mergeRels:true}) yield node return node", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use single quotes
" (a2:ALabel {name:'a2'})-[:HAS_REL{p:'r2'}]->(b1)," + | ||
" (a3:ALabel {name:'a3'})<-[:HAS_REL{p:'r3'}]-(b1)," + | ||
" (a4:ALabel {name:'a4'})-[:HAS_REL{p:'r4'}]->(b4:BLabel {name:'b4'})"); | ||
Map<String,Object> params = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this form?
" (n1)-[:DRIVE{since:2017}]->(n5)," + | ||
" (n2)-[:HAS{since:2013}]->(n6)"); | ||
|
||
testCall(db, "MATCH (a1:Person{name:'John'}), (a2:Person {name:'Tom'})" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this statement is werid.
row -> { | ||
assertTrue(row.get("node") != null); | ||
assertTrue(row.get("node") instanceof Node); | ||
Node resultingNode = (Node)(row.get("node")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just cast it
assertEquals(4,resultingNode.getDegree(Direction.OUTGOING)); | ||
assertEquals(1,c.getDegree(Direction.INCOMING)); | ||
assertEquals(true, r.isType(RelationshipType.withName("WORKS_FOR"))); | ||
assertEquals(Arrays.asList( 2015L , 2018L).toArray(), new ArrayBackedList(r.getProperty("since")).toArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just two lists or Sets
346fdad
to
789f61b
Compare
@@ -335,12 +336,19 @@ public void categorize( | |||
}); | |||
} | |||
|
|||
private Node mergeNodes(Node source, Node target, boolean delete, RefactorConfig conf) { | |||
private Node mergeNodes(Node source, Node target, boolean delete, Map<String, Object> config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change RefactoringConfig to Map here? and then that map is not even used in the method?
…at allows to combine relationships of the same type and direction
@jexp pr updated |
Thanks a lot |
…combine relationships of the same type and direction (#850)
@jexp for merging rels, procedure mergeNodes read the config parameter mergeRels: true/false.
If relationships have same start and end nodes are merged into one and properties combined.
ex. with this data set (we want to merge nodes :Person):
we have
if relationships have different end or start nodes (related to direction) are maintained both and properties combine into all relationships
ex. with this data set (we want to merge nodes :Person):
we have: