Skip to content

Commit

Permalink
Fixed issue with properties in CloneSubgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBergstrand committed Jan 7, 2025
1 parent 444989b commit a0a74ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ apply from: "licenses-source-header.gradle"

ext {
publicDir = "${project.rootDir}"
neo4jVersionEffective = project.hasProperty("neo4jVersionOverride") ? project.getProperty("neo4jVersionOverride") : "2025.01.0"
neo4jVersionEffective = project.hasProperty("neo4jVersionOverride") ? project.getProperty("neo4jVersionOverride") : "2025.01.0-SNAPSHOT"
testContainersVersion = '1.20.2'
apacheArrowVersion = '15.0.0'
}
2 changes: 1 addition & 1 deletion core/src/main/java/apoc/refactor/GraphRefactoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private static Node cloneNode(final Transaction tx, final Node node, final Set<S

private static void cloneRel(Relationship base, Node from, Node to, final Set<String> skipProps) {
final var rel = from.createRelationshipTo(to, base.getType());
rel.getAllProperties().forEach((k, v) -> {
base.getAllProperties().forEach((k, v) -> {
if (skipProps.isEmpty() || !skipProps.contains(k)) rel.setProperty(k, v);
});
}
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/java/apoc/refactor/CloneSubgraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,36 @@ public void testCloneSubgraph_With_Standins_For_Node1_Should_Have_RootB() {
});
}

@Test
public void testCloneSubgraph_With_Properties_On_Relationships_Preserved() {
try (final var tx = db.beginTx();
final var clean = tx.execute("MATCH (n) DETACH DELETE n");
final var create = tx.execute("CREATE (:A)-[:R{id:\"ID1\"}]->(:B)");
final var clone = tx.execute(
"""
MATCH (n)-[r:R]->(oldB:B)
WITH oldB, COLLECT(DISTINCT n) AS nodes
CREATE (newB:B)
WITH oldB, newB, nodes
MATCH (m)-[r]-(n) WHERE n IN nodes
WITH oldB, newB, nodes, COLLECT(DISTINCT r) AS rels
MATCH (s) WHERE NOT s:B
WITH oldB, newB, nodes, rels, COLLECT(DISTINCT [s, s]) + [[oldB, newB]] AS standinNodes
CALL apoc.refactor.cloneSubgraph(nodes, rels, {standinNodes:standinNodes})
YIELD input, output
MATCH (old) WHERE ID(old) = input
CREATE (output)-[r:importedFrom{created_on:datetime()}]->(old)
RETURN output
""");
final var res = tx.execute("MATCH (n)-[r]->(m) RETURN r.id AS id"); ) {
assertThat(res.stream()).containsExactlyInAnyOrder(Map.of("id", "ID1"), Map.of("id", "ID1"));
}
}

@Test
public void
testCloneSubgraph_With_Standins_For_RootA_And_Oddball_Should_Have_RootB_And_Use_Node_12_In_Place_Of_Oddball() {
Expand Down

0 comments on commit a0a74ff

Please sign in to comment.