This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
[master < E-meta] Add MAGE meta module docs #1017
Open
imilinovic
wants to merge
5
commits into
master
Choose a base branch
from
E-mage-meta-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,199 @@ | ||||||||||
--- | ||||||||||
id: meta | ||||||||||
title: meta | ||||||||||
sidebar_label: meta | ||||||||||
--- | ||||||||||
|
||||||||||
import Tabs from '@theme/Tabs'; | ||||||||||
import TabItem from '@theme/TabItem'; | ||||||||||
import RunOnSubgraph from '../../templates/_run_on_subgraph.mdx'; | ||||||||||
|
||||||||||
export const Highlight = ({children, color}) => ( | ||||||||||
<span | ||||||||||
style={{ | ||||||||||
backgroundColor: color, | ||||||||||
borderRadius: '2px', | ||||||||||
color: '#fff', | ||||||||||
padding: '0.2rem', | ||||||||||
}}> | ||||||||||
{children} | ||||||||||
</span> | ||||||||||
); | ||||||||||
|
||||||||||
|
||||||||||
The **meta** module provides a set of procedures for generating metadata about the database. | ||||||||||
|
||||||||||
[](https://github.com/memgraph/mage/tree/main/cpp/meta_module) | ||||||||||
|
||||||||||
| Trait | Value | | ||||||||||
| ------------------- | ----------------------------------------------------- | | ||||||||||
| **Module type** | <Highlight color="#FB6E00">**algorithm**</Highlight> | | ||||||||||
| **Implementation** | <Highlight color="#FB6E00">**C++**</Highlight> | | ||||||||||
| **Parallelism** | <Highlight color="#FB6E00">**sequential**</Highlight> | | ||||||||||
|
||||||||||
### Procedures | ||||||||||
|
||||||||||
## stats | ||||||||||
|
||||||||||
The stats procedure returns the following metadata about the graph: | ||||||||||
- `labelCount` ➡ number of unique labels in nodes | ||||||||||
- `relationshipTypeCount` ➡ number of unique relationship types (labels) | ||||||||||
- `nodeCount` ➡ number of nodes in the graph | ||||||||||
- `relationshipCount` ➡ number of relationships in the graph | ||||||||||
- `labels` ➡ map with the following (key, value) pairs: | ||||||||||
- `label` : number_of_occurrences | ||||||||||
- `relationshipTypes` ➡ map with the following (key, value) pairs: | ||||||||||
- `(:label)-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->(:label)` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `relationshipTypesCount` ➡ map with the following (key, value) pairs: | ||||||||||
- `relationship_type` : number_of_occurrences | ||||||||||
- `stats` ➡ map which contains all of the above | ||||||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
It is split into two version which return the same metadata: | ||||||||||
- stats_online - works in **O(1)** and requires setting up a trigger | ||||||||||
- stats_offline - traverses the whole graph | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you listing the same outputs three times then?
can be in the intro, or each in its own section. It's confusing like this + different from all the other mage pages |
||||||||||
|
||||||||||
### `stats_online(update_stats)` | ||||||||||
|
||||||||||
Retrieves the graph metadata in **O(1)** complexity. Requires setting up the following trigger: | ||||||||||
|
||||||||||
```cypher | ||||||||||
CREATE TRIGGER meta_trigger BEFORE COMMIT EXECUTE CALL meta.update(createdObjects, deletedObjects, removedVertexProperties, removedEdgeProperties, setVertexLabels, removedVertexLabels); | ||||||||||
``` | ||||||||||
This procedure tracks the data created/deleted/modified after the trigger was added. If you want to return the metadata about the whole graph you need to run the *stats_online* procedure with the *update_stats* flag set to true **once**. That flag will cause the procedure to traverse the whole graph to update the metadata. After that you can always run with the *update_stats* flag set to false and the procedure will return the metadata in **O(1)** complexity. | ||||||||||
|
||||||||||
|
||||||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
#### Input: | ||||||||||
|
||||||||||
- `update_stats: bool (default=false)` ➡ if true traverses the whole graph to update the metadata otherwise returns the stored metadata | ||||||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
#### Output: | ||||||||||
|
||||||||||
- `labelCount: int` ➡ number of unique labels in nodes | ||||||||||
- `relationshipTypeCount: int` ➡ number of unique relationship types (labels) | ||||||||||
- `nodeCount: int` ➡ number of nodes in the graph | ||||||||||
- `relationshipCount: int` ➡ number of relationships in the graph | ||||||||||
- `labels: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `label` : number_of_occurrences | ||||||||||
- `relationshipTypes: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `(:label)-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->(:label)` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `relationshipTypesCount: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `relationship_type` : number_of_occurrences | ||||||||||
- `stats` ➡ map which contains all of the above | ||||||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
#### Usage: | ||||||||||
|
||||||||||
Running stats on the following graph: | ||||||||||
```cypher | ||||||||||
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 3}) CREATE (a)-[:Relation2]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:Relation2]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 5}) CREATE (a)-[:Relation2]->(b); | ||||||||||
``` | ||||||||||
|
||||||||||
```cypher | ||||||||||
CALL meta.stats_online() YIELD stats; | ||||||||||
``` | ||||||||||
|
||||||||||
```plaintext | ||||||||||
+-------------------------------------------------------+ | ||||||||||
| stats | | ||||||||||
+-------------------------------------------------------+ | ||||||||||
| | | ||||||||||
|{ | | ||||||||||
| "labelCount": 1, | | ||||||||||
| "labels": { | | ||||||||||
| "Node": 6 | | ||||||||||
| }, | | ||||||||||
| "nodeCount": 6, | | ||||||||||
| "propertyKeyCount": 1, | | ||||||||||
| "relationshipCount": 6, | | ||||||||||
| "relationshipTypeCount": 2, | | ||||||||||
| "relationshipTypes": { | | ||||||||||
| "()-[:Relation1]->()": 3, | | ||||||||||
| "()-[:Relation1]->(:Node)": 3, | | ||||||||||
| "()-[:Relation2]->()": 3, | | ||||||||||
| "()-[:Relation2]->(:Node)": 3, | | ||||||||||
| "(:Node)-[:Relation1]->()": 3, | | ||||||||||
| "(:Node)-[:Relation2]->()": 3 | | ||||||||||
| }, | | ||||||||||
| "relationshipTypesCount": { | | ||||||||||
| "Relation1": 3, | | ||||||||||
| "Relation2": 3 | | ||||||||||
| } | | ||||||||||
|} | | ||||||||||
| | | ||||||||||
+-------------------------------------------------------+ | ||||||||||
``` | ||||||||||
|
||||||||||
### `stats_offline()` | ||||||||||
|
||||||||||
Retrieves the graph metadata by traversing the whole graph. *stats_online* should be preferred because of the better complexity unless you don't want to use triggers. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
#### Output: | ||||||||||
|
||||||||||
- `labelCount: int` ➡ number of unique labels in nodes | ||||||||||
- `relationshipTypeCount: int` ➡ number of unique relationship types (labels) | ||||||||||
- `nodeCount: int` ➡ number of nodes in the graph | ||||||||||
- `relationshipCount: int` ➡ number of relationships in the graph | ||||||||||
- `labels: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `label` : number_of_occurrences | ||||||||||
- `relationshipTypes: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `(:label)-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->(:label)` : number_of_occurrences | ||||||||||
- `()-[:relationship_type]->()` : number_of_occurrences | ||||||||||
- `relationshipTypesCount: Map[string: int]` ➡ map with the following (key, value) pairs: | ||||||||||
- `relationship_type` : number_of_occurrences | ||||||||||
- `stats` ➡ map which contains all of the above | ||||||||||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
|
||||||||||
#### Usage: | ||||||||||
|
||||||||||
Running stats on the following graph: | ||||||||||
```cypher | ||||||||||
MERGE (a:Node {id: 0}) MERGE (b:Node {id: 1}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 1}) MERGE (b:Node {id: 2}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 2}) MERGE (b:Node {id: 0}) CREATE (a)-[:Relation1]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 3}) CREATE (a)-[:Relation2]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 4}) CREATE (a)-[:Relation2]->(b); | ||||||||||
MERGE (a:Node {id: 3}) MERGE (b:Node {id: 5}) CREATE (a)-[:Relation2]->(b); | ||||||||||
``` | ||||||||||
|
||||||||||
```cypher | ||||||||||
CALL meta.stats_offline() YIELD stats; | ||||||||||
``` | ||||||||||
|
||||||||||
```plaintext | ||||||||||
+-------------------------------------------------------+ | ||||||||||
| stats | | ||||||||||
+-------------------------------------------------------+ | ||||||||||
| | | ||||||||||
|{ | | ||||||||||
| "labelCount": 1, | | ||||||||||
| "labels": { | | ||||||||||
| "Node": 6 | | ||||||||||
| }, | | ||||||||||
| "nodeCount": 6, | | ||||||||||
| "propertyKeyCount": 1, | | ||||||||||
| "relationshipCount": 6, | | ||||||||||
| "relationshipTypeCount": 2, | | ||||||||||
| "relationshipTypes": { | | ||||||||||
| "()-[:Relation1]->()": 3, | | ||||||||||
| "()-[:Relation1]->(:Node)": 3, | | ||||||||||
| "()-[:Relation2]->()": 3, | | ||||||||||
| "()-[:Relation2]->(:Node)": 3, | | ||||||||||
| "(:Node)-[:Relation1]->()": 3, | | ||||||||||
| "(:Node)-[:Relation2]->()": 3 | | ||||||||||
| }, | | ||||||||||
| "relationshipTypesCount": { | | ||||||||||
| "Relation1": 3, | | ||||||||||
| "Relation2": 3 | | ||||||||||
| } | | ||||||||||
|} | | ||||||||||
| | | ||||||||||
+-------------------------------------------------------+ | ||||||||||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a procedure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stats is not a procedure but it made sense to me to write about it since stats_online and stats_offline do the same thing (described in stats) so I wrote it as some sort of summary