skip to Main Content

I have been working on Apache age and have a question on my mind. How are vertices and edges stored in Apache age i.e what kind of data structure is used by age to store vertices and edges and how can you actually retrieve all the vertices and edges separately?

7

Answers


  1. AGE uses two types of tables to store graph data i.e. vertex tables and edge tables. Vertex tables contain the properties of each vertex, while edge tables contain the properties of each edge, as well as the source and destination vertices.
    While the underlined architecture uses PostgreSQL’s relational database management system to store and manage graph data. PostgreSQL uses B-tree (and some other) indexes to quickly retrieve data from tables, which makes querying large graphs relatively fast and efficient.

    Login or Signup to reply.
  2. Apache AGE basically stores vertices and edges in the form of tables only where each vertex is represented by a row in a table, and each column in the row represents a property of the vertex. Similarly, each edge is represented by a row in a separate table, and each column in the row represents property of the edge.

    You can simply retrieve all vertices using the following command:

    SELECT * FROM cypher('graph_name', $$
    MATCH (v)
    RETURN v
    $$) as (v agtype);
    

    For edges you can use relationships() command to get the edges and their relationships. For example :

    SELECT * FROM cypher('graph', $$
    MATCH p = (v)-[*]->(b)
    RETURN relationships(p)
    $$) as (v agtype);
    
    Login or Signup to reply.
  3. In addition to han and Aditya’s answers, you can retrieve the vertices and edges which AGE stores as postgreSQL tables using the following SQL queries

    SELECT * FROM "<graph_name>"._ag_label_vertex;
    

    and

    SELECT * FROM "<graph_name>"._ag_label_edges; 
    
    Login or Signup to reply.
  4. First of all to store all the vertices and edges, you have the following ways, and you can try any of them:

    1. Vertx Table
    2. Edge Table
    3. Indexes
      You can use either to store them. Now, For the retrieval of all the vertices and edges, we can use the SQL queries.

    Query for the retrieval of vertices:

    SELECT * FROM vertex_table;

    Query for the retrieval of edges:

    SELECT * FROM edge_table;

    And now if we have vertices connected with IDs 1 and 2, we can retrieve all the edges as follows

    SELECT * FROM edge_table WHERE source = 1 AND destination = 2;

    Feel free to reach out in case of any confusion.

    Login or Signup to reply.
  5. Here is a very practical way to understand this.

    Let us define some vertexes and edges like so:

    SELECT * FROM cypher('test_graph',$$
    CREATE
    (C_Major: scale {
    notes: ['C', 'D', 'E', 'F', 'G', 'A', 'B'],
    tonic: 'C',
    mode: 'Ionian'
    }),
    (G_Major: scale {
    notes: ['G', 'A', 'B', 'C', 'D', 'E', 'F#'],
    tonic: 'G',
    mode: 'Ionian'
    }),
    (C_Major)-[modulates: modulation {type: 'phrase'}]->(G_Major)
    RETURN C_Major, modulates, G_Major
    $$)
    as (C_Major agtype, modulates agtype, G_Major agtype);
    

    Having defined them try the following commands:

    • Graph Table
    dt test_graph.*
    
    • Vertex
    d test_graph.scale
    
    • Edge
    d test_graph.modulation
    

    These will display how and what the vertexes and edges are saved as in the Relational DB.

    As for retrieving the vertices and edges:

    d test_graph._ag_label_vertex
    
    d test_graph._ag_label_edge
    

    Modifying each command with d+ will show the child tables for that type (vertex or edge) as well. These commands are for running within the RDB.

    Login or Signup to reply.
  6. Apache AGE stores graph information in separate schemas/namespaces for each graphs.

    Thus for each graph we will have a schema with that graph’s name. In that particular schema the various graph specific tables, relations and other things are kept.

    We can get the vertices by:

        SELECT * FROM <graph_name>._ag_label_vertex;
    

    and edges by:

        SELECT * FROM <graph_name>._ag_label_edges;
    
    Login or Signup to reply.
  7. Vertices and edges are stored in PgSQl tables using schema that is used for graph processing. For vertices they are stored in table using primary key column which represent vertex ID and properties while edges are separately stored in table representing the source and dest vertex id and edges.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search