NebulaGraph is a kind of graph database, which is different from the table relationship of mysql database. The whole space is divided into vertex (tag) and edge, forming a network relationship of graph. Each vertex has a globally unique vertex id(vid).
Specific help documents: https://docs.nebula-graph.com.cn/
Here are the details:
1, Library level operation statement
1. View all libraries:
show spaces;
2. View library information:
describe space sqlLineage;
2, tag statement - determines the type and bearing information of vertices
1. View all tag s:
show tags;
2. Create tag:
The variable length type is string and the fixed length type is fixed_string(), Boolean value bool and date timestamp. You can set the default value. For example, you can set the default function now() and timestamp() for date. When you insert a vertex with this tag and do not pass parameters to this attribute, the default value will be set to the current time.
create tag phone(name string,color fixed_string(5),size double,isSell bool default false,ct timestamp default timestamp());
3. Delete tag:
Note that the tag with index cannot be deleted, otherwise it will report confict!
drop tag phone;
4. To view individual tag information:
describe tag phone;
3, edge type statement - determines the type and bearing information of the edge
1. View all edge type s
show edges;
2. Create edge type
create edge flow1(degree int);
3. Delete edge type
Note that the edge type with index cannot be deleted, otherwise it will report: confirm!
drop edge flow1;
4. To view single edge type information:
describe edge flow1;
4, Vertex statement
1. Insert vertex:
When inserting a vertex, you must indicate the vid of the vertex, here is hash("iphone")
insert vertex phone(name,color,size) values hash("iphone"):("iphone","black",6.8);
2. Delete vertex:
delete vertex hash("iphone")
5, Edge statement
1. Insert edge
When inserting an edge, you must indicate which vertex the edge is from to which vertex, and also through the vid of the corresponding vertex. Here is the hash("iphone") vertex to hash("xiaomi") vertex, and the attribute is degree.
insert edge flow1(degree) values hash("iphone")->hash("xiaomi"):(1);
2. Delete edge
delete edge flow2 hash("iphone")->hash("xiaomi");
6, Non indexed query statement
1. View individual vertex information
fetch prop on phone hash("iphone");
2. View single edge information
fetch prop on flow1 hash("iphone")->hash("xiaomi")
3. Jump query
The following example shows that from the vertex whose vid is hash("iphone"), query all qualified vertices that jump 1 to 10 times according to the edge of flow1, and output the vid information of the vertex.
go 1 to 10 steps from hash("iphone") over flow1;
This statement can be modified. In the following example, yield can control the output content$ surface show of yes yes answer edge of lower one individual section spot , still can with use It represents the next node of the corresponding edge. You can also use It refers to the next node of the corresponding edge. You can also use ^torepresent the previous node of the corresponding edge. After finding the node, take the name attribute of the phone on the node as the alias nm, and then output it.
go 1 to 10 steps from hash("iphone") over flow1 yield $$.phone.name as nm;
As shown in the following example, the edge can be conditionally qualified
go 1 to 10 steps from hash("iphone") over flow1 where flow1.degree >3 yield $$.phone.name as nm;
As shown in the following example, the vertex (this is the lower vertex) can be conditionally limited, the output name is additionally de duplicated, and the data type of the output size is forcibly converted.
go 1 to 10 steps from hash("iphone") over flow1 where $$.phone.size > 6 yield distinct($$.phone.name) as nm,toInteger($$.phone.size) as size;
As in the following example, the pipe symbol is introduced, and $- refers to the aliased nodes output by the statement before the pipe symbol. First sort by size, and then take the first three.
go 1 to 10 step from hash("iphone") over flow1 where $$.phone.size >6 yield $$.phone.name as name,toInteger($$.phone.size) as size,flow1.degree as degree| order by $-.size |limit 3;
7, Index statement
Indexes are divided into vertex indexes and edge indexes:
1. View all indexes under the current space
(1) Vertex index
show tag indexes;
(2) Edge index
show edge indexes;
2. Create index
(1) Vertex (edge) full field index
create tag index index1 on phone();
(2) Vertex (edge) single field index
create tag index index2 on phone(name(10));
(3) Vertex (edge) composite field index
create tag index index3 on phone(name(10),size);
Note that the length of variable length fields must be specified when creating an index, as shown in name(10) above
3. View index creation statements
show create tag index index3;
4. View index properties
describe tag index index2;
5. Delete index
drop tag index index3;
8, Indexed query statement
You need to index the corresponding tag (edge) before inserting data to execute the following statement
1. Batch query vertices (edges) by criteria – lookup
lookup on phone where phone.size == 6.8
2. Batch query vertices (edges) by criteria – match
match (p:phone) where p.size > 6.0 return p;