Skip to content

Commit ec41efe

Browse files
matea16DavIvekJosipmrdencolinbarrygitbuda
authored
Memgraph 3.4 (#1308)
* init * Add scalar_kind options to vector index (#1313) * extend docs with scalar_kind options * extend docs with scalar_kind examples * Update pages/querying/vector-search.mdx --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Get hops counter function (#1323) Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Add `text.replace`, `text.regReplace`, `text.distance` functions (#1321) * Add text functions documentation * Add indentation * Fix indentation --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * doc: Update docs for current GraphQL support (#1327) - Clarify what are pre-requisites and which dependencies are installed as part of the article - Update example to use the syntax and settings needed for `@neo4j/graphql` 7.2.0. - Expand list of what is now supported. * Add `refactor.mergeNodes` query module (#1322) * Add mergeNodes documentation * Add dot --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Start adding changelog items * All memgraph release notes are in place, TODO: check again tomorrow * Start adding MAGE changelog items * Add docs for vector edge index. (#1329) * add docs for vector index on edges * add info about vector index to SHOW INDEX INFO query * fix spelling mistake --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Add all MAGE changelog items * Add docs for missing `date` and `mgps` functions (#1330) * doc: Add docs for `date.convert_format` * doc: Tidy `date` docs - Clarify the behaviour of `convert_format` - Correct the underlying language of the module: Python, not C++. * doc: Add docs for `mgps.validate_predicate` * doc: Actually add mpgs page --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Add docs for replica recovery (#1325) Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> * Complete changelog * Concurrent index creation docs (#1332) * concurrent index doc * typos * fixes * Apply suggestions from code review * update --------- Co-authored-by: Matea Pesic <80577904+matea16@users.noreply.github.com> Co-authored-by: matea16 <mateapesic@hotmail.com> * remove lab from release notes --------- Co-authored-by: David Ivekovic <david.ivekovic@memgraph.io> Co-authored-by: Josipmrden <josip.mrden@memgraph.io> Co-authored-by: colinbarry <colin.barry@memgraph.io> Co-authored-by: Marko Budiselic <marko.budiselic@memgraph.com> Co-authored-by: Andi Skrgat <andi8647@gmail.com> Co-authored-by: Ivan Milinović <44698587+imilinovic@users.noreply.github.com>
1 parent 6fd30ff commit ec41efe

File tree

13 files changed

+685
-62
lines changed

13 files changed

+685
-62
lines changed

next.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ export default withNextra({
299299
destination: '/advanced-algorithms/available-algorithms/migrate',
300300
permanent: true
301301
},
302+
{
303+
source: '/memgraph/query-modules/mgps.py',
304+
destination: '/advanced-algorithms/available-algorithms/mgps',
305+
permanent: true
306+
},
302307
{
303308
source: '/mage/algorithms/traditional-graph-analytics/node-similarity-algorithm',
304309
destination: '/advanced-algorithms/available-algorithms/node_similarity',

pages/advanced-algorithms/available-algorithms.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ If you want to know more and learn how this affects you, read our [announcement]
8686
| [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. |
8787
| [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. |
8888
| [csv_utils](/advanced-algorithms/available-algorithms/csv_utils) | C++ | An utility module for creating and deleting CSV files. |
89-
| [date](/advanced-algorithms/available-algorithms/date) | C++ | The `date` module provides various utilities to handle date and time operations within the Cypher query language. |
89+
| [date](/advanced-algorithms/available-algorithms/date) | Python | The `date` module provides various utilities to handle date and time operations within the Cypher query language. |
9090
| [do](/advanced-algorithms/available-algorithms/do) | C++ | A module that is used to define conditions not expressible in Cypher to control query execution. |
9191
| [export_util](/advanced-algorithms/available-algorithms/export_util) | Python | A module for exporting the graph database in different formats (JSON). |
9292
| [graph_analyzer](/advanced-algorithms/available-algorithms/graph_analyzer) | Python | This Graph Analyzer query module offers insights about the stored graph or a subgraph. |
@@ -100,6 +100,7 @@ If you want to know more and learn how this affects you, read our [announcement]
100100
| [meta](/advanced-algorithms/available-algorithms/meta) | C++ | Provides information about graph nodes and relationships. |
101101
| [meta_util](/advanced-algorithms/available-algorithms/meta_util) | Python | A module that contains procedures describing graphs on a meta-level. |
102102
| [migrate](/advanced-algorithms/available-algorithms/migrate) | Python | A module that can access data from a MySQL, SQL Server or Oracle database. |
103+
| [mgps](/advanced-algorithms/available-algorithms/mgps) | Python | A module containing various utility functions. |
103104
| [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. |
104105
| [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. |
105106
| [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. |

pages/advanced-algorithms/available-algorithms/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default {
3838
"meta_util": "meta_util",
3939
"meta": "meta",
4040
"migrate": "migrate",
41+
"mgps": "mgps",
4142
"neighbors": "neighbors",
4243
"node_similarity": "node_similarity",
4344
"node": "node",

pages/advanced-algorithms/available-algorithms/date.mdx

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ Memgraph for managing time-based data.
2727
| Trait | Value |
2828
| ------------------- | ------------------- |
2929
| **Module type** | util |
30-
| **Implementation** | C++ |
31-
| **Graph direction** | directed/undirected |
32-
| **Edge weights** | weighted/unweighted |
30+
| **Implementation** | Python |
3331
| **Parallelism** | sequential |
3432

3533
## Procedures
@@ -152,6 +150,8 @@ YIELD parsed RETURN parsed;
152150
+---------------------+
153151
```
154152

153+
## Functions
154+
155155
### `add()`
156156

157157
Adds two numeric values representing quantities of time in specific units.
@@ -187,4 +187,49 @@ RETURN date.add(100, "day", 24, "h") AS sum;
187187
+---------------------+
188188
| 101 |
189189
+---------------------+
190+
```
191+
192+
### `convert_format()`
193+
194+
Converts a string containing a date or time in one specified format into a
195+
string of another specified date or time format.
196+
197+
{<h4 className="custom-header"> Input: </h4>}
198+
199+
- `temporal: string` ➡ The date to be converted.
200+
- `currentFormat: string` ➡ The format of the input `temporal` string date.
201+
- `convertTo: string` ➡ The required output date string format.
202+
203+
`conert_format` supports the following formats for both `currentFormat` and
204+
`convertTo`:
205+
206+
- `basic_iso_date` - `YYYYMMDD` (e.g., `20111203`)
207+
- `iso_local_date` - `YYYY-MM-DD` (e.g., `2011-12-03`)
208+
- `iso_offset_date` - `YYYY-MM-DD±hh:mm` (e.g., `2011-12-03+01:00`)
209+
- `iso_date` - `YYYY-MM-DD` or `YYYY-MM-DD±hh:mm` (e.g., `2011-12-03+01:00`)
210+
- `iso_local_time` - `HH:MM:SS` (e.g., `10:15:30`)
211+
- `iso_offset_time` - `HH:MM:SS±hh:mm` (e.g., `10:15:30+01:00`)
212+
- `iso_time` - `HH:MM:SS` or `HH:MM:SS±hh:mm` (e.g, `10:15:30+01:00`)
213+
- `iso_local_date_time` - `YYYY-MM-DDTHH:MM:SS` (e.g., `2011-12-03T10:15:30`)
214+
- `iso_offset_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm` (e.g., `2011-12-03T10:15:30+01:00`)
215+
- `iso_zoned_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm[ZoneName]` (e.g., `2011-12-03T10:15:30+01:00[Europe/Paris]`)
216+
- `iso_date_time` - `YYYY-MM-DDTHH:MM:SS±hh:mm[ZoneName]` (e.g, `2011-12-03T10:15:30+01:00[Europe/Paris]`)
217+
218+
{<h4 className="custom-header"> Output: </h4>}
219+
220+
The output of this function is a `string` value representing the `temporal` input
221+
expressed in the required `convertTo` format.
222+
223+
{<h4 className="custom-header"> Usage: </h4>}
224+
225+
```cypher
226+
RETURN date.convert_format('2011-12-03T10:15:30+01:00[Europe/Paris]', 'iso_zoned_date_time', 'iso_offset_date_time') AS dt;
227+
```
228+
229+
```plaintext
230+
+-----------------------------+
231+
| dt |
232+
+-----------------------------+
233+
| "2011-12-03T10:15:30+01:00" |
234+
+-----------------------------+
190235
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: mgps
3+
description: Memgraph's mgps module contains various utility functions for general-purpose tasks.
4+
---
5+
6+
import { Steps } from 'nextra/components'
7+
import { Callout } from 'nextra/components'
8+
import { Cards } from 'nextra/components'
9+
import GitHub from '/components/icons/GitHub'
10+
11+
# mgps
12+
13+
A module containing utility functions for general purpose tasks.
14+
15+
<Cards>
16+
<Cards.Card
17+
icon={<GitHub />}
18+
title="Source code"
19+
href="https://github.com/memgraph/memgraph/blob/master/query_modules/mgps.py"
20+
/>
21+
</Cards>
22+
23+
| Trait | Value |
24+
| ------------------- | ---------- |
25+
| **Module type** | util |
26+
| **Implementation** | Python |
27+
| **Parallelism** | sequential |
28+
29+
## Functions
30+
31+
### `validate_predicate()`
32+
33+
Raises an exception if the given predicate yields `true`; otherwise returns
34+
`true`. This is useful when checking assertions in `WHERE` clauses, because it
35+
means you can filter out data that doesn't meet your validation criteria, and
36+
provide an error if the validation fails for a specific reason you want to
37+
highlight.
38+
39+
{<h4 className="custom-header"> Input: </h4>}
40+
- `predicate: boolean` ➡ Predicate condition to evaluate.
41+
- `message: string` ➡ The text of the error message raised if the predicate
42+
yields `true`. This can contain placeholder, such as `%s`, which are
43+
interpolated from the `params` argument.
44+
- `params: list` ➡ The list of parameters to substitute into placeholders in `message`.
45+
46+
{<h4 className="custom-header"> Output: </h4>}
47+
48+
- `true: boolean` ➡ This function either returns `true`, or aborts the query by
49+
raising an exception.
50+
51+
{<h4 className="custom-header"> Usage: </h4>}
52+
53+
Use the following query to validate that `age` is never negative, and to raise
54+
an exception if the predicate is `true`.
55+
56+
```cypher
57+
MATCH (n:User)
58+
WHERE mgps.validate_predicate(n.age < 0, "Invalid age: %i", [n.age])
59+
RETURN n;
60+
```

pages/advanced-algorithms/available-algorithms/refactor.mdx

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,4 +965,93 @@ CALL refactor.rename_type_property("distance_in_km","distance",[r]) YIELD relati
965965
+---------------------------------------+
966966
| 1 |
967967
+---------------------------------------+
968-
```
968+
```
969+
970+
### `mergeNodes()`
971+
972+
Merges the properties, labels and relationships for the source nodes to the target node.
973+
974+
{<h4 className="custom-header"> Input: </h4>}
975+
976+
- `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.
977+
If subgraph is not specified, the algorithm is computed on the entire graph by default.
978+
979+
- `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.
980+
- `config: Map` ➡ Configuration parameters:
981+
- `properties: string` ➡ values: `combine`, `override/overwrite`, `discard`:
982+
- `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
983+
- `override` ➡ last property in the list wins
984+
- `overwrite` ➡ same as `override`
985+
- `discard` ➡ discard the properties of the nodes - value will be null
986+
- `.*: string` ➡ equivalent to properties
987+
- `mergeRels: boolean` ➡ specify whether the relationships will be merged into the target node or discarded.
988+
989+
{<h4 className="custom-header"> Output: </h4>}
990+
991+
- `node: Node` ➡ Merged node with updated properties, labels and relationships.
992+
993+
{<h4 className="custom-header"> Usage: </h4>}
994+
995+
Create a graph using the queries below:
996+
997+
```cypher
998+
CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'})
999+
CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'});
1000+
```
1001+
1002+
Use the procedure to merge the nodes:
1003+
1004+
```cypher
1005+
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'})
1006+
CALL refactor.merge_nodes([n1, n2], {properties: 'combine'}) YIELD node
1007+
RETURN node.name as name, node.age as age, node.city as city, node.country as country;
1008+
```
1009+
1010+
or
1011+
1012+
```cypher
1013+
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'})
1014+
CALL refactor.merge_nodes([n1, n2], {`.*`: 'combine'}) YIELD node
1015+
RETURN node.name as name, node.age as age, node.city as city, node.country as country;
1016+
```
1017+
1018+
The procedure returns the merged node properties:
1019+
1020+
```plaintext
1021+
+-----------------------------------------------------+
1022+
| name | age | city | country |
1023+
+-----------------------------------------------------+
1024+
| ["Alice", "Bob"] | [30, 25] | "New York" | "USA" |
1025+
+-----------------------------------------------------+
1026+
```
1027+
1028+
The following scenario will also merge the relationships:
1029+
1030+
Create a graph using the queries below:
1031+
1032+
```cypher
1033+
CREATE (n1:Person {name: 'Alice', age: 30, city: 'New York'})
1034+
CREATE (n2:Person {name: 'Bob', age: 25, country: 'USA'})
1035+
CREATE (n3:Person {name: 'Charlie', age: 35, city: 'London'})
1036+
CREATE (n1)-[:KNOWS {since: 2020}]->(n2)
1037+
CREATE (n2)-[:WORKS_WITH {project: 'Project X'}]->(n3)
1038+
CREATE (n3)-[:FRIENDS_WITH {since: 2019}]->(n1);
1039+
```
1040+
1041+
Use the procedure to merge the nodes and relationships:
1042+
1043+
```cypher
1044+
MATCH (n1:Person {name: 'Alice'}), (n2:Person {name: 'Bob'}), (n3:Person {name: 'Charlie'})
1045+
CALL refactor.merge_nodes([n1, n2, n3], {properties: 'combine', mergeRels: true}) YIELD node
1046+
RETURN node.name as name, outDegree(node) as out_degree, inDegree(node) as in_degree;
1047+
```
1048+
1049+
The procedure returns the merged node properties:
1050+
1051+
```plaintext
1052+
+----------------------------------------------------+
1053+
| name | inDegree | outDegree |
1054+
+----------------------------------------------------+
1055+
| ["Alice", "Bob", "Charlie"] | 3 | 3 |
1056+
+----------------------------------------------------+
1057+
```

pages/advanced-algorithms/available-algorithms/text.mdx

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ If subgraph is not specified, the algorithm is computed on the entire graph by d
120120

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

123-
Use the following query to insert the parameters to the placeholders in the sentence:
123+
Use the following queries to insert the parameters to the placeholders in the sentence:
124124

125125
```cypher
126126
CALL text.format("Memgraph is the number {} {} in the world.", [1, "graph database"])
@@ -137,3 +137,106 @@ Result:
137137
| "Memgraph is the number 1 graph database in the world. "|
138138
+---------------------------------------------------------+
139139
```
140+
141+
### `replace()`
142+
143+
Replace each substring of the given string that matches the given regular expression with the given replacement.
144+
145+
{<h4 className="custom-header"> Input: </h4>}
146+
147+
- `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.
148+
If subgraph is not specified, the algorithm is computed on the entire graph by default.
149+
- `text: string` ➡ Text that needs to be replaced.
150+
- `regex: string` ➡ Regular expression by which to replace the string.
151+
- `replacement: string` ➡ Target string to replace the matched string.
152+
153+
{<h4 className="custom-header"> Usage: </h4>}
154+
155+
Use the following queries to do text replacement:
156+
157+
```cypher
158+
RETURN text.replace('Hello World!', '[^a-zA-Z]', '') AS result;
159+
```
160+
161+
Result:
162+
163+
```plaintext
164+
+--------------+
165+
| result |
166+
+--------------+
167+
| "HelloWorld" |
168+
+--------------+
169+
```
170+
171+
```cypher
172+
RETURN text.replace('MAGE is a Memgraph Product', 'MAGE', 'GQLAlchemy') AS result;
173+
```
174+
175+
Result:
176+
177+
```plaintext
178+
+------------------------------------+
179+
| result |
180+
+---------- -------------------------+
181+
| "GQLAlchemy is a Memgraph Product" |
182+
+------------------------------------+
183+
```
184+
185+
### `regReplace()`
186+
187+
Replace each substring of the given string that matches the given regular expression with the given replacement.
188+
189+
{<h4 className="custom-header"> Input: </h4>}
190+
191+
- `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.
192+
If subgraph is not specified, the algorithm is computed on the entire graph by default.
193+
- `text: string` ➡ Text that needs to be replaced.
194+
- `regex: string` ➡ Regular expression by which to replace the string.
195+
- `replacement: string` ➡ Target string to replace the matched string.
196+
197+
{<h4 className="custom-header"> Usage: </h4>}
198+
199+
Use the following query to do text replacement:
200+
201+
```cypher
202+
RETURN text.regreplace("Memgraph MAGE Memgraph MAGE", "MAGE", "GQLAlchemy") AS output;
203+
```
204+
205+
Result:
206+
207+
```plaintext
208+
+---------------------------------------+
209+
| result |
210+
+---------------------------------------+
211+
| "GQLAlchemy MAGE Memgraph GQLAlchemy" |
212+
+---------------------------------------+
213+
```
214+
215+
### `distance()`
216+
217+
Compare the given strings with the Levenshtein distance algorithm.
218+
219+
{<h4 className="custom-header"> Input: </h4>}
220+
221+
- `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.
222+
If subgraph is not specified, the algorithm is computed on the entire graph by default.
223+
- `text1: string` ➡ Source string.
224+
- `text2: string` ➡ Destination string for comparison.
225+
226+
{<h4 className="custom-header"> Usage: </h4>}
227+
228+
Use the following query to calculate distance between texts:
229+
230+
```cypher
231+
RETURN text.distance("Levenshtein", "Levenstein") AS result;
232+
```
233+
234+
Result:
235+
236+
```plaintext
237+
+--------+
238+
| result |
239+
+--------+
240+
| 1 |
241+
+--------+
242+
```

0 commit comments

Comments
 (0)