Map Functions

In AGE, a map is a data structure that stores a collection of key-value pairs. Each key in a map is unique and associated with a corresponding value. This structure resembles a dictionary in Python or an object in JavaScript, providing an efficient way to organize and retrieve data by key. This section covers functions that enable you to generate and manipulate maps effectively.

vertex_stats()

The vertex_stats() function extracts metadata from a vertex. When you pass a vertex to vertex_stats(), it returns a structured map containing the following key-value pairs:

  • id: The unique identifier assigned to the vertex.
  • label: The label or type used to classify the vertex.
  • in_degree: The number of incoming edges directed toward the vertex.
  • out_degree: The number of outgoing edges originating from the vertex.
  • self_loops: The number of self-loop edges associated with the vertex.

Syntax: vertex_stats(vertex)

Data Preparation

-- Create the graph.
SELECT create_graph('vertex_stats_graph');

-- Create vertices and edges.
SELECT * FROM cypher('vertex_stats_graph', $$
CREATE (:Person {name: 'John Donne'})-[:WROTE]->(:Poem {title: 'Holy Sonnet XIV'})
$$) AS (a agtype);

Query

SELECT * FROM cypher('vertex_stats_graph', $$
MATCH (v:Poem {title: 'Holy Sonnet XIV'})
RETURN vertex_stats(v)
$$) AS (vertex_stats agtype);

Result

vertex_stats
{"id": 1407374883553281, "label": "Poem", "in_degree": 1, "out_degree": 0, "self_loops": 0}

Retrieving Values

You can retrieve individual values from the resulting map using subscript notation:vertex_stats(vertex)["key"]