Graph-data models

A graph is a just a collection of vertices and edges. The most convincing example of a graph-data model is a social network. Each piece of information in this world is connected. To store and process information correctly, a database must embrace and store the entity and its connectivity with another entity. This is where the graph-data model kicks in. Storing and accessing nodes and relationships in a graph database is an easy, efficient, and constant-time operation that permits a user to quickly traverse and get correct information.

Mathematically, a graph is a pair G = (V, E) of sets that satisfy  ( V X V). The elements of V are the vertices or nodes of the graph, G, and the elements of E are its edges or relationships. 

Let's see a graph model of movies and actors. 

Figure 5.6: Labeled graph model of movies and actors

From the movie data model given in the preceding diagram, it's clear that we have the following vertex table:

ID Property (V)
1 (Person, Jackie Chan)
2 (Person, Dwayne Johnson)
3 (Movie, Kung Fu Panda)
4 (Movie, Moana)
5 (Movie, Skyscraper)
6 (Person, John Stevenson)
7 (Person, Ron Clements)
8 (Person, Rawson Marshall Thurber)

 

The corresponding edge table of the graph would be:

Source Destination Property(E)
1 3 ACTED_IN
2 4 ACTED_IN
2 5 ACTED_IN
6 3 DIRECTED
7 4 DIRECTED
8 5 DIRECTED

 

From the preceding diagram, the following observations can be made:

  • The data model is a graph model that shows nodes (person, movies) and relationships (ACTED_IN and DIRECTED)
  • Nodes can be labeled with one or more labels, which is good for identification
  • Nodes can contain properties where properties are stored as a key-value pair
  • Relationships can be named and directed
  • Relationships have a start and end node
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.205.2