mgps

A module containing utility functions for general purpose tasks.

TraitValue
Module typeutil
ImplementationPython
Parallelismsequential

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.

This function is equivalent to apoc.util.validatePredicate.

Input:

  • 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.

Output:

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

Usage:

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

MATCH (n:User)
WHERE mgps.validate_predicate(n.age < 0, "Invalid age: %i", [n.age])
RETURN n;

await_indexes()

A no-op compatibility shim for Neo4j’s db.awaitIndexes. Some clients (notably the Neo4j Spark / PySpark connector) call db.awaitIndexes during initialization to block until pending indexes are online. Memgraph builds indexes synchronously, so there is nothing to wait for — this procedure exists purely so those clients can connect without changes.

This procedure is equivalent to db.awaitIndexes.

Input:

  • seconds: integer ➡ Accepted for parity with the Neo4j signature. The value is ignored.
CALL mgps.await_indexes(300);

version()

Returns the Memgraph server version as a string. Provided as the Memgraph equivalent of apoc.version for compatibility with Neo4j-style clients.

This function is equivalent to apoc.version.

Output:

  • version: string ➡ The Memgraph server version.

Usage:

RETURN mgps.version();