CREATE SPACE play_space (partition_num = 10, replica_factor = 1, vid_type = INT64) COMMENT = "运动员库表空间";
CREATE SPACE play_space (partition_num = 10, replica_factor = 1, vid_type = FIXED_STRING(32)) COMMENT = "运动员库表空间";
drop SPACE play_space;
CREATE tag player (name string NULL COMMENT "姓名", age int8 NULL COMMENT "年龄") COMMENT = "球员";
CREATE tag team (name string NULL COMMENT "球队名称") COMMENT = "归属球队";
SHOW TAGS;
describe TAG player;
单条插入示例:
insert vertex player(name,age) values 100:("詹姆斯",38);
insert vertex player(name,age) values 101:("库里",34);
insert vertex player(name,age) values 102:("杜兰特",34);
批量插入示例:
insert vertex team(name) values 200:("洛杉矶湖人队"),201:("金州勇士队"),202:("布鲁克林篮网队");
指定属性查看示例:
fetch prop on player 100,101,102 YIELD properties(vertex).name,properties(vertex).age;
查询全部属性示例 :
fetch prop on team 200,201,202 YIELD properties(vertex);
delete vertex 100;
CREATE edge follow (attention_rate int16 NULL COMMENT "关注度") COMMENT = "球员关注度关联表";
CREATE edge service (start_time int32 NULL COMMENT "开始时间", end_time int32 NULL COMMENT "结束时间") COMMENT = "球员服役时间关联表";
SHOW edges;
describe edge service;
单条插入示例:
insert edge follow(attention_rate) values 100->101:(20);
insert edge follow(attention_rate) values 101->102:(50);
insert edge follow(attention_rate) values 102->103:(80);
批量插入示例:
insert edge service(start_time,end_time) values 100->200:(2003,2023),101->201:(2009,2023),102->203:(2007,2023);
单条查看示例:
fetch prop on follow 100->101 YIELD properties(edge);
批量查看示例:
fetch prop on service 100->200,101->201 YIELD properties(edge).start_time,properties(edge).end_time;
CREATE {TAG | EDGE} INDEX [IF NOT EXISTS]
ON { | } ([]) [COMMENT = ''];
示例
//点
CREATE TAG INDEX IF NOT EXISTS index_player ON player(name(30), age);
//边
CREATE EDGE INDEX IF NOT EXISTS index_follow ON follow(attention_rate);
REBUILD {TAG | EDGE} INDEX ;
示例
//点
REBUILD TAG INDEX index_name;
//边
REBUILD EDGE INDEX index_follow;
语句从一个或多个点开始,沿着一条或多条边遍历,返回YIELD子句中指定的信息。
GO [[ TO] STEPS ] FROM
OVER [{REVERSELY | BIDIRECT}]
[ WHERE ]
YIELD [DISTINCT]
[{ SAMPLE | }]
[| GROUP BY { | expression> | } YIELD ]
[| ORDER BY [{ASC | DESC}]]
[| LIMIT [,] ];
从vid为100的球员开始找,沿着service边找到终点vid,输出起点vid和终点vid及其信息
GO FROM 100 OVER service YIELD id($^),properties($^),id($$),properties($$);
备注:
$^ :表示边的起点
$$ :表示边的终点
properties() :返回点/边的所有属性
可以获得点或边的属性
查看点
语法:
FETCH PROP ON {
YIELD
示例:
fetch prop on player 100 YIELD properties(vertex);
语法:
FETCH PROP ON
YIELD
示例:
fetch prop on follow 100->101 YIELD properties(edge);
语句是基于索引的,和WHERE子句一起使用,查找符合特定条件的数据,要先创建索引
LOOKUP ON { | }
[WHERE [AND ...]]
YIELD [AS ];
[AS ] [, [AS ] ...];
a.找出点中名称为詹姆斯的球员
LOOKUP ON player WHERE player.name == "詹姆斯" YIELD properties(vertex);
b.找出球员中名字经库里开始,并且年龄在34和38两个值之前的球员
LOOKUP ON player WHERE player.name STARTS WITH "库里" AND player.age IN [34,38] YIELD properties(vertex).name, properties(vertex).age;
c.根据条件查看边
LOOKUP ON follow WHERE follow.attention_rate > 20 YIELD properties(edge);
d.统计边或者点的数量
LOOKUP ON player YIELD id(vertex)| YIELD COUNT(*) AS Player_Number;
LOOKUP ON follow YIELD edge AS e| YIELD COUNT(*) AS Follow_Number;
可以灵活的描述各种图模式,但是它依赖索引去匹配 Nebula Graph 中的数据模型,性能也还需要调优,要先创建索引
MATCH
查找球员名称为的点并返回
MATCH (v:player{name:"杜兰特"}) RETURN v