diff --git a/pages/advanced-algorithms/available-algorithms/path.mdx b/pages/advanced-algorithms/available-algorithms/path.mdx index a34654d22..d2992050c 100644 --- a/pages/advanced-algorithms/available-algorithms/path.mdx +++ b/pages/advanced-algorithms/available-algorithms/path.mdx @@ -44,7 +44,7 @@ node-relationship-node order. {

Input:

} -- `path: Path` ➡ The given path. +- `path: Path` ➡ The given path. If `null`, the function returns `null`. {

Output:

} @@ -78,8 +78,10 @@ paths can't be combined. {

Input:

} -- `first: Path` ➡ The first path. -- `second: Path` ➡ The second path. +- `first: Path` ➡ The first path. If `null`, the function returns the second path. +- `second: Path` ➡ The second path. If `null`, the function returns the first path. + +If both paths are `null`, the function returns `null`. {

Output:

} @@ -114,14 +116,26 @@ The function returns a subpath of the given path. {

Input:

} -- `path: Path` ➡ The given path. -- `offset: int = 0` ➡ The first node index from the given path to be included in the subpath. -- `length: int = -1` ➡ Length of the subpath. If set to -1 the subpath will end on the final node of the given path. +- `path: Path` ➡ The given path. If `null`, the function returns `null`. +- `offset: int = 0` ➡ The first node index from the given path to be included in + the subpath. A negative offset is read as `0`, and an offset past the end of + the given path starts the subpath at its final node. +- `length: int = -1` ➡ Length of the subpath. If set to -1 the subpath will end + on the final node of the given path. A length reaching past the end of the + given path ends the subpath on its final node, and any other negative length + returns a subpath with no relationships. {

Output:

} - `Path` ➡ The subpath of the given path. + +An offset or length outside the given path is adjusted to the nearest subpath +rather than raising an error, so bounds computed from an expression such as +`length(path)` can be passed without guarding them first. The shortest subpath +the function returns is a single node. + + {

Usage:

} Use the following query to return a subpath of the given path: @@ -143,6 +157,27 @@ The result is returned in shortened form with () signifying nodes and [] signify +------------------------------------------------------------------------------------------------------+ ``` +Use the following query to see how bounds outside the given path are adjusted: + +```cypher +MATCH path = (:Node1)-[:CONNECTED*4]->(:Node5) +RETURN path.slice(path, -5, 2) AS negative_offset, + path.slice(path, 10, -1) AS offset_past_end, + path.slice(path, 1, -3) AS negative_length; +``` + +The negative offset starts the subpath at the first node, the offset past the +end returns the final node on its own, and the negative length returns a +subpath with no relationships: + +```plaintext ++--------------------------------------------------------+--------------------------------------------------------+--------------------------------------------------------+ +| negative_offset | offset_past_end | negative_length | ++--------------------------------------------------------+--------------------------------------------------------+--------------------------------------------------------+ +| (:Node1)-[:CONNECTED]->(:Node2)-[:CONNECTED]->(:Node3) | (:Node5) | (:Node2) | ++--------------------------------------------------------+--------------------------------------------------------+--------------------------------------------------------+ +``` + ## Procedures ### `create()`