Graph Structure
Before creating a graph, it is essential to design an appropriate graph structure based on the specific scenario. This establishes the data model, delivers understanding of the graph, and enables efficient information retrieval.
A graph structure is defined by the labels and properties of nodes and edges, detailing the types of nodes and edges involved and the attributes they possess. The structure of the graph can evolve over time, making it easy to adjust as needed.
Below is an example of a graph structure:
Label
Labels are used to group and reference nodes or edges of the same types. The above graph data model includes the following labels:
- Node labels:
User
,Product
andType
- Edge labels:
Purchased
andHas
In Ultipa, label creation using GQL is not yet supported. Instead, schemas created by UQL serve as the equivalent of labels in GQL. Key characteristics include:
- Each node is assigned exactly one node label, and each edge exactly one edge label. Labels are specified during the insertion of nodes and edges.
- Reassigning a different label to a node or edge is not permitted.
- While node labels and edge labels must be unique, a node label and an edge label may share the same name.
Property
Properties are used to store additional attributes for nodes and edges, such as name
and gender
for nodes labeled User
. Each property comprises its name and value.
In Ultipa, property creation using GQL is not yet supported. Instead, properties provided by system (system properties) or created by UQL (custom properties) are used as equivalents in GQL. Key characteristics include:
- A property is associated with a label, meaning all nodes or edges with the same label share the same set of properties.
- You can specify values for properties during the insertion of nodes or edges, and later update or remove these values as needed.
- The type of a property is either pre-defined or defined during its creation.
Graph Elements
Node and Edge
Graph elements refer to nodes and edges, the two fundamental units of a graph. Typically, nodes represent entities and edges depict the relationships between nodes.
This is a graph created following the above data model:
Unique Identifiers
Nodes have two system properties _id
(String) and _uuid
(Uint64) serving as unique identifiers. When inserting new nodes, the _id
value can be manually assigned, or it will be automatically generated by the system if not provided. On the other hand, the _uuid
is automatically generated and cannot be specified manually.
Edges have the system property _uuid
(Uint64) as unique identifier. Like nodes, the value of _uuid
for edges is system-generated cannot be manually specified.
Edge Direction
In Ultipa, all edges are directed, each having a source node and a destination node, pointing from the former to the latter. The source node and destination node are also called the endpoints of an edge. For example, (:User {name: "maysoo", gender: "female"})
is the source node of three edges labeled Purchased
, and each edge has distinct destination node labeled Product
.
Assume an edge e
with the source node a
and the destination node b
. In path (a)-[e]->(b)
, the edge e
points to the right. Conversely, in the path (b)<-[e]-(a)
, the same edge e
points to the left.
Self-Loops
An edge that connects a node to itself, where the source node and destination node are the same, is called a self-loop.
Paths
A path is a sequence of an odd number of connected graph elements. A path always (1) starts and ends with a node, and (2) alternates between nodes and edges. A path may comprise a single node.
In Ultipa, by default, a path allows nodes to be revisited but not edges (i.e., TRAIL
is the default path mode).
Subpath
A subpath is a path fully contained in another path.