DEV Community

Cover image for How Data is Represented - The Internals of Apache AGE
Wendel Fernandes de Lana
Wendel Fernandes de Lana

Posted on

How Data is Represented - The Internals of Apache AGE

Introduction

In this article I will give an introduction to the internals of Apache AGE, specifically how data is represented in AGE.

Prerequisites

A basic knowledge of PostgreSQL or any other Relational Database Management System (RDBMS), including an understanding of tables, schemas, and commonly used SQL queries such as SELECT, INSERT, DELETE, and UPDATE, is essential. Additionally, proficiency in JSON (JavaScript Object Notation) is also necessary.

How Data is Represented

Apache AGE has extended PostgreSQL with a new data type called "agtype," which is based on PostgreSQL's JSONB implementation. The agtype data type provides support for three custom data types: vertices, edges, and paths, which enable graph database functionality within the PostgreSQL ecosystem.
In AGE, data is represented using a graph model, which consists of vertices and edges. Vertices represent entities in the data, such as people, places, or things, and edges represent the relationships or connections between those entities.
Each vertex and edge can have a set of properties, which are key-value pairs that provide additional information about the entity or relationship being represented.
A path refers to a sequence of edges that connect two vertices in a graph, which may include zero or more edges and vertices, and it can be either directed or undirected.

An agtype vertex consists of a graph ID, a label, and a set of properties

{
"id": 844424930131969,
"label": "person",
"properties": {"key": "value"}
}::vertex

An edge is defined by its graph ID, a label that describes its relationship to the vertices it connects, the graph IDs of its start and end vertices, and a set of properties

{
"id": 1125899906842625,
"label": "reports_to",
"start_id": 844424930131969,
"end_id": 844424930131970,
"properties": {"key": "value"}
}::edge

A path is a list of alternating vertices and edges

[vertex, edge, vertex, ...]::path

Apache AGE repository: https://github.com/apache/age
Apache AGE website: https://age.apache.org

Top comments (0)