Skip to main content

meta_util

A module that contains procedures describing graphs on a meta-level.

docs-source

TraitValue
Module typeutil
ImplementationPython
Parallelismsequential

Procedures

info

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 to true, the graph schema will include properties count information.

Output:

  • nodes: List[Map] ➡ List of distinct node objects with their count. If include_properties is set to true, the node object contains properties count too.
  • relationships: List[Map] ➡ List of distinct relationship objects with their count. If include_properties is set to true, 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;
info

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 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);

Example - Get graph schema with properties count

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);