From 8d357a54cf503458c8d6602cda9fd5999e822013 Mon Sep 17 00:00:00 2001 From: Amber1990Zhang <42762957+Amber1990Zhang@users.noreply.github.com> Date: Tue, 11 Feb 2020 16:58:40 +0800 Subject: [PATCH 1/3] add bidirect --- .../go-syntax.md | 27 ++++++++++++++---- .../go-syntax.md | 28 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index aa194d4c957..2050c0b6ff7 100644 --- a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -3,11 +3,10 @@ `GO` 是 **Nebula Graph** 中最常用的关键字,可以指定过滤条件(如 `WHERE`)遍历图数据并获取点和边的属性,还能以指定顺序(`ORDER BY ASC | DESC`)返回指定数目(`LIMIT`)的结果。 >`GO` 的用法与 SQL 中的 `SELECT` 类似,重要区别是 `GO` 必须从遍历一系列的节点开始。 - ```ngql GO [ STEPS ] FROM - OVER [REVERSELY] + OVER [REVERSELY] [BIDIRECT] [ WHERE [ AND | OR expression ...]) ] YIELD | YIELDS [DISTINCT] @@ -22,12 +21,11 @@ [AS ] [, [AS ] ...] ``` -* [ STEPS ] 指定查询 N 跳。 +* [ \ STEPS ] 指定查询 N 跳。 * 为逗号隔开的节点 ID,或特殊占位符 `$-.id` (参看 `PIPE` 用法)。 * 为图遍历返回的边类型列表。 -* [ WHERE ] 指定被筛选的逻辑条件,WHERE 可用于起点,边及终点,同样支持逻辑关键词 AND、OR、NOT,详情参见 [WHERE](where-syntax.md) 的用法。 -* YIELD [DISTINCT] 以列的形式返回结果,并可对列进行重命名。详情参看 `YIELD` - 用法。`DISTINCT` 的用法与 SQL 相同。 +* [ WHERE \ ] 指定被筛选的逻辑条件,WHERE 可用于起点,边及终点,同样支持逻辑关键词 AND、OR、NOT,详情参见 WHERE 的用法。 +* YIELD [DISTINCT] 以列的形式返回结果,并可对列进行重命名。详情参看 `YIELD` 用法。`DISTINCT` 的用法与 SQL 相同。 ## 示例 @@ -162,4 +160,21 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ ---------------------------- ``` +<<<<<<< HEAD 遍历所有关注 100 号球员的球员,找出这些球员服役的球队,筛选年龄大于 20 岁的球员并返回这些球员姓名和其服役的球队名称。如果此处不指定 `YIELD`,则默认返回每条边目标点的 `vid`。 +======= +遍历 follow 125 号球员的所有球员,找出这些球员服役的球队,筛选年龄大于 35 岁的球员并返回这些球员姓名和其服役的球队名称。如果此处不指定 `YIELD`,则默认返回每条边目标点的 `vid`。 + +## 双向遍历 + +目前 **Nebula Graph** 支持使用关键词 `BIDIRECT` 进行双向遍历,语法为: + +```ngql + GO FROM + OVER REVERSELY + WHERE (expression [ AND | OR expression ...])   + YIELD | YIELDS  [DISTINCT] +``` + +例如:TODO +>>>>>>> add bidirect diff --git a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index dae8d95ec68..f7970b3cbdd 100644 --- a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -5,11 +5,10 @@ It indicates to traverse in a graph with specific filters (the `WHERE` clause), to fetch properties of vertices and edges, and return results (the `YIELD` clause) with given order (the `ORDER BY ASC | DESC` clause) and numbers (the `LIMIT` clause). > The syntax of `GO` statement is very similar to `SELECT` in SQL. Notice that the major difference is that `GO` must start traversing from a (set of) vertex (vertices). - ```ngql GO [ STEPS ] FROM - OVER [REVERSELY] + OVER [REVERSELY] [BIDIRECT] [ WHERE [ AND | OR expression ...]) ] YIELD | YIELDS [DISTINCT] @@ -25,11 +24,11 @@ It indicates to traverse in a graph with specific filters (the `WHERE` clause), [AS ] [, [AS ] ...] ``` -* [ STEPS ] specifies the N query hops -* is either a list of vertices' vids separated by comma(,), or a special place holder `$-.id` (refer `PIPE` syntax). +* [ \ STEPS ] specifies the N query hops +* is either a list of node's vid separated by comma(,), or a special place holder `$-.id` (refer `PIPE` syntax). * is a list of edge types which graph traversal can go through. -* [ WHERE ] extracts only those results that fulfill the specified conditions. WHERE syntax can be conditions for src-vertex, the edges, and dst-vertex. The logical AND, OR, NOT are also supported. See [WHERE Syntax](where-syntax.md) for more information. -* YIELD [DISTINCT] statement returns the result in column format and rename as an alias name. See `YIELD`-syntax for more information. The `DISTINCT` syntax works the same as SQL. +* [ WHERE \ ] extracts only those results that fulfill the specified conditions. WHERE syntax can be conditions for src-vertex, the edges, and dst-vertex. The logical AND, OR, NOT are also supported. See [WHERE Syntax](where-syntax.md) for more information. +* YIELD [DISTINCT] statement returns the result in column format and rename as an alias name. See `YIELD` syntax for more information. The `DISTINCT` syntax works the same as SQL. ## Examples @@ -165,4 +164,21 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ ---------------------------- ``` +<<<<<<< HEAD The above query first traverses players that follow player 100 and finds the teams they serve, then filter players who are older than 20, and finally it returns their names and teams. Of course, you can query without specifying `YIELD`, which will return the `vids` of the dest vertices of each edge by default. +======= +The above query first traverses players that follow player 125 and finds the teams they serve, then filter players who are older than 35, and finally it returns their names and teams. Of course, you can query without specifying `YIELD`, which will return the `vids` of the dest vertices of each edge by default. + +## Traverse Bidirect + +Currently, **Nebula Graph** supports traversing reversely using keyword `BIDIRECT`, the syntax is: + +```ngql + GO FROM + OVER REVERSELY + WHERE (expression [ AND | OR expression ...])   + YIELD | YIELDS  [DISTINCT] +``` + +For example: TODO +>>>>>>> add bidirect From 55fc9df109737132fdd1456c2c72368d889a3075 Mon Sep 17 00:00:00 2001 From: Amber1990Zhang <42762957+Amber1990Zhang@users.noreply.github.com> Date: Mon, 2 Mar 2020 09:50:24 +0800 Subject: [PATCH 2/3] add example bidirect --- .../go-syntax.md | 29 ++++++++++++---- .../go-syntax.md | 33 ++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index 2050c0b6ff7..1de166eb4ce 100644 --- a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -148,7 +148,11 @@ nebula> GO FROM 100 OVER follow, serve YIELD follow.degree, serve.start_year; 例如: ```ngql -nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src -- 返回 100 +``` + +```ngql +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._dst AS id | \ GO FROM $-.id OVER serve WHERE $^.player.age > 20 YIELD $^.player.name AS FriendOf, $$.team.name AS Team; ============================ @@ -160,10 +164,7 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ ---------------------------- ``` -<<<<<<< HEAD 遍历所有关注 100 号球员的球员,找出这些球员服役的球队,筛选年龄大于 20 岁的球员并返回这些球员姓名和其服役的球队名称。如果此处不指定 `YIELD`,则默认返回每条边目标点的 `vid`。 -======= -遍历 follow 125 号球员的所有球员,找出这些球员服役的球队,筛选年龄大于 35 岁的球员并返回这些球员姓名和其服役的球队名称。如果此处不指定 `YIELD`,则默认返回每条边目标点的 `vid`。 ## 双向遍历 @@ -171,10 +172,24 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ ```ngql GO FROM - OVER REVERSELY + OVER BIDIRECT WHERE (expression [ AND | OR expression ...])   YIELD | YIELDS  [DISTINCT] ``` -例如:TODO ->>>>>>> add bidirect +例如: + +```ngql +nebula> GO FROM 102 OVER follow BIDIRECT +=============== +| follow._dst | +=============== +| 101 | +--------------- +| 103 | +--------------- +| 135 | +--------------- +``` + +上述语句同时返回 102 关注的球员及关注 102 的球员。 diff --git a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index f7970b3cbdd..e416222328c 100644 --- a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -152,7 +152,11 @@ Currently, **Nebula Graph** supports traversing reversely using keyword `REVERSE For example: ```ngql -nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src -- returns 100 +``` + +```ngql +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._dst AS id | \ GO FROM $-.id OVER serve WHERE $^.player.age > 20 YIELD $^.player.name AS FriendOf, $$.team.name AS Team; ============================ @@ -164,21 +168,32 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src AS id | \ ---------------------------- ``` -<<<<<<< HEAD -The above query first traverses players that follow player 100 and finds the teams they serve, then filter players who are older than 20, and finally it returns their names and teams. Of course, you can query without specifying `YIELD`, which will return the `vids` of the dest vertices of each edge by default. -======= -The above query first traverses players that follow player 125 and finds the teams they serve, then filter players who are older than 35, and finally it returns their names and teams. Of course, you can query without specifying `YIELD`, which will return the `vids` of the dest vertices of each edge by default. +The above query first traverses players that follow player 100 and finds the teams they serve, then filter players who are older than 20, and finally it returns their names and teams. Of course, you can query without specifying YIELD, which will return the vids of the dest vertices of each edge by default. ## Traverse Bidirect -Currently, **Nebula Graph** supports traversing reversely using keyword `BIDIRECT`, the syntax is: +Currently, **Nebula Graph** supports traversing along in and out edges using keyword `BIDIRECT`, the syntax is: ```ngql GO FROM - OVER REVERSELY + OVER BIDIRECT WHERE (expression [ AND | OR expression ...])   YIELD | YIELDS  [DISTINCT] ``` -For example: TODO ->>>>>>> add bidirect +For example: + +```ngql +nebula> GO FROM 102 OVER follow BIDIRECT +=============== +| follow._dst | +=============== +| 101 | +--------------- +| 103 | +--------------- +| 135 | +--------------- +``` + +The above query returns players followed by 102 and follow 102 at the same time. From ddc221b980ea6086f07f273ed2d085c89d4773a0 Mon Sep 17 00:00:00 2001 From: Amber1990Zhang <42762957+Amber1990Zhang@users.noreply.github.com> Date: Mon, 2 Mar 2020 10:50:59 +0800 Subject: [PATCH 3/3] add semicolon --- .../2.data-query-and-manipulation-statements/go-syntax.md | 4 ++-- .../2.data-query-and-manipulation-statements/go-syntax.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index 1de166eb4ce..7f317173499 100644 --- a/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-CN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -148,7 +148,7 @@ nebula> GO FROM 100 OVER follow, serve YIELD follow.degree, serve.start_year; 例如: ```ngql -nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src -- 返回 100 +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src; -- 返回 100 ``` ```ngql @@ -180,7 +180,7 @@ nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._dst AS id | \ 例如: ```ngql -nebula> GO FROM 102 OVER follow BIDIRECT +nebula> GO FROM 102 OVER follow BIDIRECT; =============== | follow._dst | =============== diff --git a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md index e416222328c..abd0a968107 100644 --- a/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md +++ b/docs/manual-EN/2.query-language/4.statement-syntax/2.data-query-and-manipulation-statements/go-syntax.md @@ -152,7 +152,7 @@ Currently, **Nebula Graph** supports traversing reversely using keyword `REVERSE For example: ```ngql -nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src -- returns 100 +nebula> GO FROM 100 OVER follow REVERSELY YIELD follow._src; -- returns 100 ``` ```ngql @@ -184,7 +184,7 @@ Currently, **Nebula Graph** supports traversing along in and out edges using key For example: ```ngql -nebula> GO FROM 102 OVER follow BIDIRECT +nebula> GO FROM 102 OVER follow BIDIRECT; =============== | follow._dst | ===============