Skip to content
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

5.26 LTS clone subgraph properties fix #717

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/main/java/apoc/ApocExtensionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void start() {
}

// For APOC extended, the Cypher Procedures listener is both a service and a listener
// To stop needing to keep a Map containing it as an object, which stops it being
// To stop needing to keep a Map containing it as an object, which stops it being
// cleaned up, we check for all APOC services which are also listeners and register them here
for (Object service : services.values()) {
if (service instanceof AvailabilityListener serviceWithAvailabilityListener) {
Expand Down
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 @@ -321,7 +321,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
Loading