meta_util
A module that contains procedures describing graphs on a meta-level.
Trait | Value |
---|---|
Module type | util |
Implementation | Python |
Parallelism | sequential |
Procedures
If you want to execute this algorithm on graph projections, subgraphs or portions of the graph, be sure to check out the guide on How to run a MAGE module on subgraphs.
schema(include_properties)
Knowing what kind of data, that is, what kind of nodes and relationships, are stored inside the database and how they're connected can be helpful. Besides that, each node or relationship can have a set of properties, and while loading the data in the database, you should be sure that a certain amount of graph objects has a particular property. That's where the number of graph objects with a particular property (property count) might come in handy.
The schema()
procedure returns a list of distinct relationships connecting distinct nodes, that is, a graph schema. If include_properties
is set to true
, the graph schema will contain additional information about properties.
Input:
include_properties: bool (default=false)
➡ If set totrue
, the graph schema will include properties count information.
Output:
nodes: List[Map]
➡ List of distinct node objects with their count. Ifinclude_properties
is set totrue
, the node object contains properties count too.relationships: List[Map]
➡ List of distinct relationship objects with their count. Ifinclude_properties
is set totrue
, the relationship object contains properties count too.
Usage:
Get graph schema without properties count:
CALL meta_util.schema()
YIELD nodes, relationships
RETURN nodes, relationships;
Get graph schema with properties count:
CALL meta_util.schema(true)
YIELD nodes, relationships
RETURN nodes, relationships;
The queries above will return results in the graph view only in Memgraph Lab version >= 2.4.0. For earlier versions of the Memgraph Lab, call UNWIND
on returned object properties nodes and edges.
Example - Get graph schema without properties count
- Create a graph
- Run the command
- Graph result
- Data result - nodes
- Data result - relationships
Create a graph by running the following Cypher query:
CREATE (n:Person {name: "Kate", age: 27})-[:IS_FRIENDS_WITH]->(m:Person:Student {name: "James", age: 30, year: "second"})-[:STUDIES_AT]->(:University {name: "University of Vienna"})
WITH n, m
CREATE (n)-[:LIVES_IN]->(:City {name: "Zagreb"})<-[:LIVES_IN]-(m);
Once the graph is created, run the following code to call the schema
procedure:
CALL meta_util.schema()
YIELD nodes, relationships
RETURN nodes, relationships;
The graph result of the schema
procedure can be seen in Memgraph Lab, and it looks like this:
Memgraph Lab can also return data results - a list of nodes and a list of relationships. Here is the obtained list of nodes:
[
{
"id": 0,
"labels": [
"Person"
],
"properties": {
"count": 1
},
"type": "node"
},
{
"id": 1,
"labels": [
"Person",
"Student"
],
"properties": {
"count": 1
},
"type": "node"
},
{
"id": 2,
"labels": [
"University"
],
"properties": {
"count": 1
},
"type": "node"
},
{
"id": 3,
"labels": [
"City"
],
"properties": {
"count": 1
},
"type": "node"
}
]
Here is the obtained list of relationships:
[
{
"end": 1,
"id": 0,
"label": "IS_FRIENDS_WITH",
"properties": {
"count": 1
},
"start": 0,
"type": "relationship"
},
{
"end": 3,
"id": 1,
"label": "LIVES_IN",
"properties": {
"count": 1
},
"start": 0,
"type": "relationship"
},
{
"end": 2,
"id": 2,
"label": "STUDIES_AT",
"properties": {
"count": 1
},
"start": 1,
"type": "relationship"
},
{
"end": 3,
"id": 3,
"label": "LIVES_IN",
"properties": {
"count": 1
},
"start": 1,
"type": "relationship"
}
]
Example - Get graph schema with properties count
- Create a graph
- Run the command
- Graph result
- Data result - nodes
- Data result - relationships
Create a graph by running the following Cypher query:
CREATE (n:Person {name: "Kate", age: 27})-[:IS_FRIENDS_WITH]->(m:Person:Student {name: "James", age: 30, year: "second"})-[:STUDIES_AT]->(:University {name: "University of Vienna"})
WITH n, m
CREATE (n)-[:LIVES_IN]->(:City {name: "Zagreb"})<-[:LIVES_IN]-(m);
Once the graph is created, run the following code to call the schema
procedure:
CALL meta_util.schema(true)
YIELD nodes, relationships
RETURN nodes, relationships;
The graph result of the schema
procedure can be seen in Memgraph Lab, and it looks like this:
Memgraph Lab can also return data results - a list of nodes and a list of relationships. Here is the obtained list of nodes:
[
{
"id": 0,
"labels": [
"Person"
],
"properties": {
"count": 1,
"properties_count": {
"age": 1,
"name": 1
}
},
"type": "node"
},
{
"id": 1,
"labels": [
"Person",
"Student"
],
"properties": {
"count": 1,
"properties_count": {
"age": 1,
"name": 1,
"year": 1
}
},
"type": "node"
},
{
"id": 2,
"labels": [
"University"
],
"properties": {
"count": 1,
"properties_count": {
"name": 1
}
},
"type": "node"
},
{
"id": 3,
"labels": [
"City"
],
"properties": {
"count": 1,
"properties_count": {
"name": 1
}
},
"type": "node"
}
]
Here is the obtained list of relationships:
[
{
"end": 1,
"id": 0,
"label": "IS_FRIENDS_WITH",
"properties": {
"count": 1,
"properties_count": {}
},
"start": 0,
"type": "relationship"
},
{
"end": 3,
"id": 1,
"label": "LIVES_IN",
"properties": {
"count": 1,
"properties_count": {}
},
"start": 0,
"type": "relationship"
},
{
"end": 2,
"id": 2,
"label": "STUDIES_AT",
"properties": {
"count": 1,
"properties_count": {}
},
"start": 1,
"type": "relationship"
},
{
"end": 3,
"id": 3,
"label": "LIVES_IN",
"properties": {
"count": 1,
"properties_count": {}
},
"start": 1,
"type": "relationship"
}
]