Skip to content

Memgraph 3.4 #1308

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

Merged
merged 17 commits into from
Jul 10, 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
5 changes: 5 additions & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ export default withNextra({
destination: '/advanced-algorithms/available-algorithms/migrate',
permanent: true
},
{
source: '/memgraph/query-modules/mgps.py',
destination: '/advanced-algorithms/available-algorithms/mgps',
permanent: true
},
{
source: '/mage/algorithms/traditional-graph-analytics/node-similarity-algorithm',
destination: '/advanced-algorithms/available-algorithms/node_similarity',
Expand Down
3 changes: 2 additions & 1 deletion pages/advanced-algorithms/available-algorithms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ If you want to know more and learn how this affects you, read our [announcement]
| [collections](/advanced-algorithms/available-algorithms/collections) | C++ | The collections module is a collection manipulation module that offers functions to work with lists in Cypher queries, allowing operations like filtering, sorting, and modification for efficient data handling. |
| [create](/advanced-algorithms/available-algorithms/create) | C++ | The create module is a set of powerful tools that provide additional capabilities for creating nodes and relationships in the Memgraph graph database. |
| [csv_utils](/advanced-algorithms/available-algorithms/csv_utils) | C++ | An utility module for creating and deleting CSV files. |
| [date](/advanced-algorithms/available-algorithms/date) | C++ | The `date` module provides various utilities to handle date and time operations within the Cypher query language. |
| [date](/advanced-algorithms/available-algorithms/date) | Python | The `date` module provides various utilities to handle date and time operations within the Cypher query language. |
| [do](/advanced-algorithms/available-algorithms/do) | C++ | A module that is used to define conditions not expressible in Cypher to control query execution. |
| [export_util](/advanced-algorithms/available-algorithms/export_util) | Python | A module for exporting the graph database in different formats (JSON). |
| [graph_analyzer](/advanced-algorithms/available-algorithms/graph_analyzer) | Python | This Graph Analyzer query module offers insights about the stored graph or a subgraph. |
Expand All @@ -100,6 +100,7 @@ If you want to know more and learn how this affects you, read our [announcement]
| [meta](/advanced-algorithms/available-algorithms/meta) | C++ | Provides information about graph nodes and relationships. |
| [meta_util](/advanced-algorithms/available-algorithms/meta_util) | Python | A module that contains procedures describing graphs on a meta-level. |
| [migrate](/advanced-algorithms/available-algorithms/migrate) | Python | A module that can access data from a MySQL, SQL Server or Oracle database. |
| [mgps](/advanced-algorithms/available-algorithms/mgps) | Python | A module containing various utility functions. |
| [neighbors](/advanced-algorithms/available-algorithms/neighbors) | C++ | The neighbors module allows users to interact with and query nodes that have direct relationships to a specified node. |
| [node](/advanced-algorithms/available-algorithms/node) | C++ | A module that provides a comprehensive toolkit for managing graph nodes, enabling creation, deletion, updating, merging, and more. |
| [nodes](/advanced-algorithms/available-algorithms/nodes) | C++ | A module that provides a comprehensive toolkit for managing multiple graph nodes, enabling linking, updating, type deduction and more. |
Expand Down
1 change: 1 addition & 0 deletions pages/advanced-algorithms/available-algorithms/_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default {
"meta_util": "meta_util",
"meta": "meta",
"migrate": "migrate",
"mgps": "mgps",
"neighbors": "neighbors",
"node_similarity": "node_similarity",
"node": "node",
Expand Down
51 changes: 48 additions & 3 deletions pages/advanced-algorithms/available-algorithms/date.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ Memgraph for managing time-based data.
| Trait | Value |
| ------------------- | ------------------- |
| **Module type** | util |
| **Implementation** | C++ |
| **Graph direction** | directed/undirected |
| **Edge weights** | weighted/unweighted |
| **Implementation** | Python |
| **Parallelism** | sequential |

## Procedures
Expand Down Expand Up @@ -152,6 +150,8 @@ YIELD parsed RETURN parsed;
+---------------------+
```

## Functions

### `add()`

Adds two numeric values representing quantities of time in specific units.
Expand Down Expand Up @@ -187,4 +187,49 @@ RETURN date.add(100, "day", 24, "h") AS sum;
+---------------------+
| 101 |
+---------------------+
```

### `convert_format()`

Converts a string containing a date or time in one specified format into a
string of another specified date or time format.

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

- `temporal: string` ➡ The date to be converted.
- `currentFormat: string` ➡ The format of the input `temporal` string date.
- `convertTo: string` ➡ The required output date string format.

`conert_format` supports the following formats for both `currentFormat` and
`convertTo`:

- `basic_iso_date` - `YYYYMMDD` (e.g., `20111203`)
- `iso_local_date` - `YYYY-MM-DD` (e.g., `2011-12-03`)
- `iso_offset_date` - `YYYY-MM-DD±hh:mm` (e.g., `2011-12-03+01:00`)
- `iso_date` - `YYYY-MM-DD` or `YYYY-MM-DD±hh:mm` (e.g., `2011-12-03+01:00`)
- `iso_local_time` - `HH:MM:SS` (e.g., `10:15:30`)
- `iso_offset_time` - `HH:MM:SS±hh:mm` (e.g., `10:15:30+01:00`)
- `iso_time` - `HH:MM:SS` or `HH:MM:SS±hh:mm` (e.g, `10:15:30+01:00`)
- `iso_local_date_time` - `YYYY-MM-DDTHH:MM:SS` (e.g., `2011-12-03T10:15:30`)
- `iso_offset_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm` (e.g., `2011-12-03T10:15:30+01:00`)
- `iso_zoned_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm[ZoneName]` (e.g., `2011-12-03T10:15:30+01:00[Europe/Paris]`)
- `iso_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm[ZoneName]` (e.g, `2011-12-03T10:15:30+01:00[Europe/Paris]`)

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

The output of this function is a `string` value representing the `temporal` input
expressed in the required `convertTo` format.

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

```cypher
RETURN date.convert_format('2011-12-03T10:15:30+01:00[Europe/Paris]', 'iso_zoned_date_time', 'iso_offset_date_time') AS dt;
```

```plaintext
+-----------------------------+
| dt |
+-----------------------------+
| "2011-12-03T10:15:30+01:00" |
+-----------------------------+
```
60 changes: 60 additions & 0 deletions pages/advanced-algorithms/available-algorithms/mgps.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: mgps
description: Memgraph's mgps module contains various utility functions for general-purpose tasks.
---

import { Steps } from 'nextra/components'
import { Callout } from 'nextra/components'
import { Cards } from 'nextra/components'
import GitHub from '/components/icons/GitHub'

# mgps

A module containing utility functions for general purpose tasks.

<Cards>
<Cards.Card
icon={<GitHub />}
title="Source code"
href="https://github.com/memgraph/memgraph/blob/master/query_modules/mgps.py"
/>
</Cards>

| Trait | Value |
| ------------------- | ---------- |
| **Module type** | util |
| **Implementation** | Python |
| **Parallelism** | sequential |

## Functions

### `validate_predicate()`

Raises an exception if the given predicate yields `true`; otherwise returns
`true`. This is useful when checking assertions in `WHERE` clauses, because it
means you can filter out data that doesn't meet your validation criteria, and
provide an error if the validation fails for a specific reason you want to
highlight.

{<h4 className="custom-header"> Input: </h4>}
- `predicate: boolean` ➡ Predicate condition to evaluate.
- `message: string` ➡ The text of the error message raised if the predicate
yields `true`. This can contain placeholder, such as `%s`, which are
interpolated from the `params` argument.
- `params: list` ➡ The list of parameters to substitute into placeholders in `message`.

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

- `true: boolean` ➡ This function either returns `true`, or aborts the query by
raising an exception.

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

Use the following query to validate that `age` is never negative, and to raise
an exception if the predicate is `true`.

```cypher
MATCH (n:User)
WHERE mgps.validate_predicate(n.age < 0, "Invalid age: %i", [n.age])
RETURN n;
```
91 changes: 90 additions & 1 deletion pages/advanced-algorithms/available-algorithms/refactor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -965,4 +965,93 @@ CALL refactor.rename_type_property("distance_in_km","distance",[r]) YIELD relati
+---------------------------------------+
| 1 |
+---------------------------------------+
```
```

### `mergeNodes()`

Merges the properties, labels and relationships for the source nodes to the target node.

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

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run.
If subgraph is not specified, the algorithm is computed on the entire graph by default.

- `nodes: List[Node]` ➡ List of nodes that will be merged into the first node of the list. Exception is thrown if the node list is empty.
- `config: Map` ➡ Configuration parameters:
- `properties: string` ➡ values: `combine`, `override/overwrite`, `discard`:
- `combine` ➡ if there are multiple values of the properties, they will be merged into a list of values. if there is only one property, then it will be the same value
- `override` ➡ last property in the list wins
- `overwrite` ➡ same as `override`
- `discard` ➡ discard the properties of the nodes - value will be null
- `.*: string` ➡ equivalent to properties
- `mergeRels: boolean` ➡ specify whether the relationships will be merged into the target node or discarded.

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

- `node: Node` ➡ Merged node with updated properties, labels and relationships.

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

Create a graph using the queries below:

```cypher
CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'})
CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'});
```

Use the procedure to merge the nodes:

```cypher
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'})
CALL refactor.merge_nodes([n1, n2], {properties: 'combine'}) YIELD node
RETURN node.name as name, node.age as age, node.city as city, node.country as country;
```

or

```cypher
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'})
CALL refactor.merge_nodes([n1, n2], {`.*`: 'combine'}) YIELD node
RETURN node.name as name, node.age as age, node.city as city, node.country as country;
```

The procedure returns the merged node properties:

```plaintext
+-----------------------------------------------------+
| name | age | city | country |
+-----------------------------------------------------+
| ["Alice", "Bob"] | [30, 25] | "New York" | "USA" |
+-----------------------------------------------------+
```

The following scenario will also merge the relationships:

Create a graph using the queries below:

```cypher
CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'})
CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'})
CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'})
CREATE (n1)-[:KNOWS {since: 2020}]->(n2)
CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3)
CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1);
```

Use the procedure to merge the nodes and relationships:

```cypher
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'})
CALL refactor.merge_nodes([n1, n2, n3], {properties: 'combine', mergeRels: true}) YIELD node
RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree;
```

The procedure returns the merged node properties:

```plaintext
+----------------------------------------------------+
| name | inDegree | outDegree |
+----------------------------------------------------+
| ["Alice", "Bob", "Charlie"] | 3 | 3 |
+----------------------------------------------------+
```
105 changes: 104 additions & 1 deletion pages/advanced-algorithms/available-algorithms/text.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ If subgraph is not specified, the algorithm is computed on the entire graph by d

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

Use the following query to insert the parameters to the placeholders in the sentence:
Use the following queries to insert the parameters to the placeholders in the sentence:

```cypher
CALL text.format("Memgraph is the number {} {} in the world.", [1, "graph database"])
Expand All @@ -137,3 +137,106 @@ Result:
| "Memgraph is the number 1 graph database in the world. "|
+---------------------------------------------------------+
```

### `replace()`

Replace each substring of the given string that matches the given regular expression with the given replacement.

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

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run.
If subgraph is not specified, the algorithm is computed on the entire graph by default.
- `text: string` ➡ Text that needs to be replaced.
- `regex: string` ➡ Regular expression by which to replace the string.
- `replacement: string` ➡ Target string to replace the matched string.

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

Use the following queries to do text replacement:

```cypher
RETURN text.replace('Hello World!', '[^a-zA-Z]', '') AS result;
```

Result:

```plaintext
+--------------+
| result |
+--------------+
| "HelloWorld" |
+--------------+
```

```cypher
RETURN text.replace('MAGE is a Memgraph Product', 'MAGE', 'GQLAlchemy') AS result;
```

Result:

```plaintext
+------------------------------------+
| result |
+---------- -------------------------+
| "GQLAlchemy is a Memgraph Product" |
+------------------------------------+
```

### `regReplace()`

Replace each substring of the given string that matches the given regular expression with the given replacement.

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

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run.
If subgraph is not specified, the algorithm is computed on the entire graph by default.
- `text: string` ➡ Text that needs to be replaced.
- `regex: string` ➡ Regular expression by which to replace the string.
- `replacement: string` ➡ Target string to replace the matched string.

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

Use the following query to do text replacement:

```cypher
RETURN text.regreplace("Memgraph MAGE Memgraph MAGE", "MAGE", "GQLAlchemy") AS output;
```

Result:

```plaintext
+---------------------------------------+
| result |
+---------------------------------------+
| "GQLAlchemy MAGE Memgraph GQLAlchemy" |
+---------------------------------------+
```

### `distance()`

Compare the given strings with the Levenshtein distance algorithm.

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

- `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run.
If subgraph is not specified, the algorithm is computed on the entire graph by default.
- `text1: string` ➡ Source string.
- `text2: string` ➡ Destination string for comparison.

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

Use the following query to calculate distance between texts:

```cypher
RETURN text.distance("Levenshtein", "Levenstein") AS result;
```

Result:

```plaintext
+--------+
| result |
+--------+
| 1 |
+--------+
```
Loading