Skip to content
Draft
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
47 changes: 41 additions & 6 deletions pages/advanced-algorithms/available-algorithms/path.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ node-relationship-node order.

{<h4 className="custom-header"> Input: </h4>}

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

{<h4 className="custom-header"> Output: </h4>}

Expand Down Expand Up @@ -78,8 +78,10 @@ paths can't be combined.

{<h4 className="custom-header"> Input: </h4>}

- `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`.

{<h4 className="custom-header"> Output: </h4>}

Expand Down Expand Up @@ -114,14 +116,26 @@ The function returns a subpath of the given path.

{<h4 className="custom-header"> Input: </h4>}

- `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.

{<h4 className="custom-header"> Output: </h4>}

- `Path` ➡ The subpath of the given path.

<Callout type="info">
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.
</Callout>

{<h4 className="custom-header"> Usage: </h4>}

Use the following query to return a subpath of the given path:
Expand All @@ -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()`
Expand Down