apoc.create.clonePathsToVirtualProcedure
| This procedure returns virtual nodes and relationships that can only be accessed by other APOC procedures. For more information, see Virtual Nodes & Relationships (Graph Projections). |
Syntax |
|
||
Description |
Takes the given |
||
Input arguments |
Name |
Type |
Description |
|
|
The paths to create virtual paths from. |
|
Return arguments |
Name |
Type |
Description |
|
|
The path result. |
|
Example
Given this dataset:
CREATE (:Person {name: 'Alice'})-[:KNOWS]->(:Person {name: 'Bob'})-[:KNOWS]->(:Person {name: 'Charlie'})
The following query collects multiple overlapping paths and returns a virtual clone of each:
MATCH p = (:Person {name: 'Alice'})-[:KNOWS*..2]->(:Person)
WITH collect(p) AS paths
CALL apoc.create.clonePathsToVirtual(paths) YIELD path
RETURN path AS virtualPath
| virtualPath |
|---|
(:Person {name: "Alice"})-[:KNOWS]→(:Person {name: "Bob"}) |
(:Person {name: "Alice"})-[:KNOWS]→(:Person {name: "Bob"})-[:KNOWS]→(:Person {name: "Charlie"}) |
Both paths above share the Alice-[:KNOWS]→Bob relationship.
Unlike calling apoc.create.clonePathToVirtual individually for each path, apoc.create.clonePathsToVirtual ensures that a relationship shared across multiple paths maps to the same virtual relationship object, avoiding duplication in the result.
The returned paths are virtual copies - any modifications made to their nodes or relationships do not affect the original graph data.