Overview
In Ultipa, a schema represents a node or edge type. Schemas are integral to the graph structure and must be defined before any node or edge data can be inserted. Each node or edge is assigned to exactly one schema.
In UQL, the operator @
denotes a schema. The expression @<schema>
specifies a particular schema, such as @Account
.
Schema in UQL analogous a label in GQL.
Default Schemas
Each graphset comes with a built-in node schema and edge schema, both named default. The two default schemas are available for unrestricted use but cannot be deleted. Additionally, their names and descriptions cannot be altered.
Showing Schemas
To retrieve information about schemas in current graphset:
// Shows all schemas
show().schema()
// Shows all node schemas
show().node_schema()
// Shows the specified node schema
show().node_schema(@user)
// Shows all edge schemas
show().edge_schema()
// Shows the specified edge schema
show().edge_schema(@transfers)
The information about schemas is organized into different tables:
- Node schemas: Stored in
_nodeSchema
(all schemas) and_nodeSchema_shard_N
(schemas with data in shardN
) tables. - Edge schemas: Stored in
_edgeSchema
(all schemas) and_edgeSchema_shard_N
(schemas with data in shardN
) tables.
Each table includes fields that provide essential details about each schema:
Field |
Description |
---|---|
id |
The id of the schema. |
name |
The name assigned to the schema. |
description |
The description given to the schema. |
status |
The current state of the schema, which can only be CREATED . |
properties |
The custom properties of the schema, with each property contains fields: name , id , type , description , index , fulltext , nullable , and lte . |
There is another table _graphCount
which gives an overview of node and edge counts across schemas. For example:
type | schema | from_schema | to_schema | count |
---|---|---|---|---|
total_nodes | 304 | |||
node | account | 120 | ||
node | movie | 184 | ||
total_edges | 956 | |||
edge | rate | account | movie | 568 |
edge | follow | account | account | 388 |
- The
count
oftotal_nodes
is the sum of nodes across all the listed node schemas. - The
count
of each individualnode
schema is the total number of nodes belonging to that specific schema. - The
count
oftotal_edges
is the sum of edges across all the listed edge schemas. - The
count
of each individualedge
schema is the number of edges belonging to that specific schema while connecting afrom_schema
node to ato_schema
node.
Creating Schemas
You can create one or more schemas using a single create()
statement. Each schema is specified by chaining a node_schema()
or edge_schema()
method.
create()
.node_schema("<schemaName>", "<schemaDesc?>")
.edge_schema("<schemaName>", "<schemaDesc?>")
...
Method | Param | Description |
---|---|---|
node_schema() or edge_schema() |
<schemaName> |
Name of the schema. Naming conventions are:
|
<schemaDesc?> |
Optional. Description of the schema. |
To create a node schema:
create().node_schema("user", "Self-registeration")
To create an edge schema:
create().edge_schema("likes")
To create multiple schemas:
create()
.node_schema("user", "Self-registeration")
.node_schema("movie")
.edge_schema("likes")
Altering Name and Description
You can modify name and description of a schema using the alter().node_schema().set()
or alter().edge_schema().set()
statement. The two default schemas cannot be altered.
To alter both name and description of the node schema @user
:
alter().node_schema(@user).set({name: "User", description: "club users"})
To alter name and remove description of the edge schema @join
:
alter().edge_schema(@join).set({name: "joins", description: ""})
To alter name of the node schema @account
:
alter().node_schema(@account).set({name: "user"})
To alter description of the edge schema @link
:
alter().edge_schema(@link).set({description: "the link between people and event"})
Dropping Schemas
You can drop one or more schemas using a single drop()
statement. Each schema is specified by chaining a node_schema()
or edge_schema()
method. The schema dropping operation runs as a job, you may run show().job(<id?>)
afterward to verify its completion.
Dropping a schema deleting the schema along with any nodes or edges belonging to it from the database. Note that the deletion of a node leads to the removal of all edges that are connected to it. The two default schemas cannot be dropped.
To drop the node schema @user
:
drop().node_schema(@user)
To drop the edge schema @likes
:
drop().edge_schema(@likes)
To drop multiple schemas:
drop().node_schema(@user).edge_schema(@likes)