Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yield for full doc #1070

Merged
merged 10 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Graph 服务主要负责处理查询请求,包括解析查询语句、校验

Parser 模块收到请求后,通过 Flex(词法分析工具)和 Bison(语法分析工具)生成的词法语法解析器,将语句转换为抽象语法树(AST),在语法解析阶段会拦截不符合语法规则的语句。

例如`GO FROM "Tim" OVER like WHERE like.likeness > 8.0 YIELD like._dst`语句转换的 AST 如下。
例如`GO FROM "Tim" OVER like WHERE properties(edge).likeness > 8.0 YIELD dst(edge)`语句转换的 AST 如下。

![AST](https://docs-cdn.nebula-graph.com.cn/docs-2.0/1.introduction/2.nebula-graph-architecture/parser-ast-tree.png)

Expand All @@ -38,7 +38,7 @@ Validator 模块对生成的 AST 进行语义校验,主要包括:

校验引用的变量是否存在或者引用的属性是否属于变量。

例如语句`$var = GO FROM "Tim" OVER like YIELD like._dst AS ID; GO FROM $var.ID OVER serve YIELD serve._dst`,Validator 模块首先会检查变量 `var` 是否定义,其次再检查属性 `ID` 是否属于变量 `var`。
例如语句`$var = GO FROM "Tim" OVER like YIELD dst(edge) AS ID; GO FROM $var.ID OVER serve YIELD dst(edge)`,Validator 模块首先会检查变量 `var` 是否定义,其次再检查属性 `ID` 是否属于变量 `var`。

- 校验类型推断

Expand All @@ -50,13 +50,13 @@ Validator 模块对生成的 AST 进行语义校验,主要包括:

查询语句中包含 `*` 时,校验子句时需要将 `*` 涉及的Schema都进行校验。

例如语句`GO FROM "Tim" OVER * YIELD like._dst, like.likeness, serve._dst`,校验`OVER`子句时需要校验所有的 Edge type,如果 Edge type 包含 `like`和`serve`,该语句会展开为`GO FROM "Tim" OVER like,serve YIELD like._dst, like.likeness, serve._dst`。
例如语句`GO FROM "Tim" OVER * YIELD dst(edge), properties(edge).likeness, dst(edge)`,校验`OVER`子句时需要校验所有的 Edge type,如果 Edge type 包含 `like`和`serve`,该语句会展开为`GO FROM "Tim" OVER like,serve YIELD dst(edge), properties(edge).likeness, dst(edge)`。

- 校验输入输出

校验管道符(|)前后的一致性。

例如语句`GO FROM "Tim" OVER like YIELD like._dst AS ID | GO FROM $-.ID OVER serve YIELD serve._dst`,Validator 模块会校验 `$-.ID` 在管道符左侧是否已经定义。
例如语句`GO FROM "Tim" OVER like YIELD dst(edge) AS ID | GO FROM $-.ID OVER serve YIELD dst(edge)`,Validator 模块会校验 `$-.ID` 在管道符左侧是否已经定义。

校验完成后,Validator 模块还会生成一个默认可执行,但是未进行优化的执行计划,存储在目录 `src/planner` 内。

Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/14.client/4.nebula-java-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ try {
ResultSet resp = session.execute(insertEdges);

// query
String query = "GO FROM \"Bob\" OVER like " + "YIELD $$.person.name, $$.person.age, like.likeness";
String query = "GO FROM \"Bob\" OVER like " + "YIELD properties($$).name, properties($$).age, properties(edge).likeness";
ResultSet resp = session.execute(query);
printResult(resp);
}finally {
Expand Down
85 changes: 47 additions & 38 deletions docs-2.0/2.quick-start/4.nebula-graph-crud.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,34 +269,37 @@ Execution succeeded (time spent 5858/6870 us)

```ngql
GO [[<M> TO] <N> STEPS ] FROM <vertex_list>
OVER <edge_type_list> [REVERSELY] [BIDIRECT]
[WHERE <expression> [AND | OR expression ...])]
YIELD [DISTINCT] <return_list>;
OVER <edge_type_list> [{REVERSELY | BIDIRECT}]
[ WHERE <conditions> ]
[YIELD [DISTINCT] <return_list>]
[| GROUP BY {col_name | expr | position} YIELD <col_name>]
[| ORDER BY <expression> [{ASC | DESC}]]
[| LIMIT [<offset_value>,] <number_rows>];
```

- `FETCH`

- 查询Tag属性

```ngql
FETCH PROP ON {<tag_name> | <tag_name_list> | *} <vid_list>
[YIELD [DISTINCT] <return_list>];
FETCH PROP ON {<tag_name>[, tag_name ...] | *}
<vid> [, vid ...]
[YIELD <return_list> [AS <alias>]];
```

- 查询边属性

```ngql
FETCH PROP ON <edge_type> <src_vid> -> <dst_vid>[@<rank>]
[, <src_vid> -> <dst_vid> ...]
[YIELD [DISTINCT] <return_list>];
FETCH PROP ON <edge_type> <src_vid> -> <dst_vid>[@<rank>] [, <src_vid> -> <dst_vid> ...]
[YIELD <output>];
```

- `LOOKUP`

```ngql
LOOKUP ON {<tag_name> | <edge_type>}
WHERE <expression> [AND expression ...])]
[YIELD <return_list>];
LOOKUP ON {<vertex_tag> | <edge_type>}
[WHERE <expression> [AND <expression> ...]]
[YIELD <return_list> [AS <alias>]];
```

- `MATCH`
Expand Down Expand Up @@ -324,14 +327,15 @@ Execution succeeded (time spent 5858/6870 us)
- 从VID为`player100`的球员开始,沿着边`follow`查找年龄大于或等于35岁的球员,并返回他们的姓名和年龄,同时重命名对应的列。

```ngql
nebula> GO FROM "player100" OVER follow WHERE $$.player.age >= 35 \
YIELD $$.player.name AS Teammate, $$.player.age AS Age;
+---------------+-----+
| Teammate | Age |
+---------------+-----+
| "Tony Parker" | 36 |
+---------------+-----+
Got 1 rows (time spent 8206/9335 us)
nebula> GO FROM "player100" OVER follow WHERE properties($$).age >= 35 \
YIELD properties($$).name AS Teammate, properties($$).age AS Age;
+-----------------+-----+
| Teammate | Age |
+-----------------+-----+
| "Tony Parker" | 36 |
+-----------------+-----+
| "Manu Ginobili" | 41 |
+-----------------+-----+
```

|子句/符号|说明|
Expand All @@ -345,15 +349,18 @@ Execution succeeded (time spent 5858/6870 us)
- 使用管道符

```ngql
nebula> GO FROM "player100" OVER follow YIELD follow._dst AS id | \
GO FROM $-.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+-----------+---------------+
| Team | Player |
+-----------+---------------+
| "Nuggets" | "Tony Parker" |
+-----------+---------------+
Got 1 rows (time spent 5055/8203 us)
nebula> GO FROM "player100" OVER follow YIELD dst(edge) AS id | \
GO FROM $-.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```

|子句/符号|说明|
Expand All @@ -369,15 +376,18 @@ Execution succeeded (time spent 5858/6870 us)
当复合语句作为一个整体提交给服务器时,其中的临时变量会在语句结束时被释放。

```ngql
nebula> $var = GO FROM "player100" OVER follow YIELD follow._dst AS id; \
GO FROM $var.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+
Got 1 rows (time spent 3103/3711 us)
nebula> $var = GO FROM "player100" OVER follow YIELD dst(edge) AS id; \
GO FROM $var.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```

### `FETCH`语句示例
Expand All @@ -391,7 +401,6 @@ nebula> FETCH PROP ON player "player100";
+----------------------------------------------------+
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
+----------------------------------------------------+
Got 1 rows (time spent 2006/2406 us)
```

!!! Note
Expand Down
12 changes: 6 additions & 6 deletions docs-2.0/3.ngql-guide/1.nGQL-overview/1.overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ Feature: Comparison of where clause
When profiling query:
"""
GO FROM "player100" OVER follow
WHERE follow.degree IN [v IN [95,99] WHERE v > 0]
YIELD follow._dst, follow.degree
WHERE properties(edge).degree IN [v IN [95,99] WHERE v > 0]
YIELD dst(edge), properties(edge).degree
"""
Then the result should be, in any order:
| follow._dst | follow.degree |
| "player101" | 95 |
| "player125" | 95 |
And the execution plan should be:
| id | name | dependencies | operator info |
| 0 | Project | 1 | |
| 1 | GetNeighbors | 2 | {"filter": "(follow.degree IN [v IN [95,99] WHERE (v>0)])"} |
| 2 | Start | | |
| id | name | dependencies | operator info |
| 0 | Project | 1 | |
| 1 | GetNeighbors | 2 | {"filter": "(properties(edge).degree IN [v IN [95,99] WHERE (v>0)])"} |
| 2 | Start | | |
```

示例中的关键字说明如下。
Expand Down
34 changes: 17 additions & 17 deletions docs-2.0/3.ngql-guide/1.nGQL-overview/ngql-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ nGQL没有严格的构建格式要求,但根据恰当而统一的风格创建n
不推荐:

```ngql
GO FROM "player100" OVER follow REVERSELY YIELD follow._dst AS id;
GO FROM "player100" OVER follow REVERSELY YIELD src(edge) AS id;
```

推荐:

```ngql
GO FROM "player100" \
OVER follow REVERSELY \
YIELD follow._dst AS id;
YIELD src(edge) AS id;
```

2. 换行写复合语句中的不同语句。

不推荐:

```ngql
GO FROM "player100" 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;
GO FROM "player100" OVER follow REVERSELY YIELD src(edge) AS id | GO FROM $-.id \
OVER serve WHERE properties($^).age > 20 YIELD properties($^).name AS FriendOf, properties($$).name AS Team;
```

推荐:

```ngql
GO FROM "player100" \
OVER follow REVERSELY \
YIELD follow._dst AS id | \
YIELD src(edge) AS id | \
GO FROM $-.id OVER serve \
WHERE $^.player.age > 20 \
YIELD $^.player.name AS FriendOf, $$.team.name AS Team;
WHERE properties($^).age > 20 \
YIELD properties($^).name AS FriendOf, properties($$).name AS Team;
```

3. 子句长度超过80个字符时,在合适的位置换行。
Expand Down Expand Up @@ -218,21 +218,21 @@ nGQL没有严格的构建格式要求,但根据恰当而统一的风格创建n
```ngql
GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id; | \
YIELD dst(edge) AS id; | \
GO FROM $-.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

支持:

```ngql
GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id | \
YIELD dst(edge) AS id | \
GO FROM $-.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

3. 在包含自定义变量的复合语句中,用英文分号结束定义变量的语句。不按规则加分号或使用管道符结束该语句会导致执行失败。
Expand All @@ -242,30 +242,30 @@ nGQL没有严格的构建格式要求,但根据恰当而统一的风格创建n
```ngql
$var = GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id \
YIELD dst(edge) AS id \
GO FROM $var.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

也不支持:

```ngql
$var = GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id | \
YIELD dst(edge) AS id | \
GO FROM $var.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```

支持:

```ngql
$var = GO FROM "player100" \
OVER follow \
YIELD follow._dst AS id; \
YIELD dst(edge) AS id; \
GO FROM $var.id \
OVER serve \
YIELD $$.team.name AS Team, $^.player.name AS Player;
YIELD properties($$).name AS Team, properties($^).name AS Player;
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ nebula> DELETE VERTEX "team1";

```ngql
# 结合管道符,删除符合条件的点。
nebula> GO FROM "player100" OVER serve WHERE serve.start_year == "2021" YIELD serve._dst AS id | DELETE VERTEX $-.id;
nebula> GO FROM "player100" OVER serve WHERE properties(edge).start_year == "2021" YIELD dst(edge) AS id | DELETE VERTEX $-.id;
```

## 删除过程与删除邻边
Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/3.ngql-guide/13.edge-statements/2.update-edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SET <update_prop>
// 用GO语句查看边的属性值。
nebula> GO FROM "player100" \
OVER serve \
YIELD serve.start_year, serve.end_year;
YIELD properties(edge).start_year, properties(edge).end_year;
+------------------+----------------+
| serve.start_year | serve.end_year |
+------------------+----------------+
Expand Down
2 changes: 1 addition & 1 deletion docs-2.0/3.ngql-guide/13.edge-statements/3.upsert-edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ SET <update_prop>
// 查看如下三个点是否有serve类型的出边,结果“Empty set”表示没有serve类型的出边。
nebula> GO FROM "player666", "player667", "player668" \
OVER serve \
YIELD serve.start_year, serve.end_year;
YIELD properties(edge).start_year, properties(edge).end_year;
Empty set

nebula> UPSERT EDGE on serve \
Expand Down
4 changes: 2 additions & 2 deletions docs-2.0/3.ngql-guide/13.edge-statements/4.delete-edge.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ nebula> DELETE EDGE serve "player100" -> "team204"@0;
```ngql
# 结合管道符,删除符合条件的边。
nebula> GO FROM "player100" OVER follow \
WHERE follow._dst == "team204" \
YIELD follow._src AS src, follow._dst AS dst, follow._rank AS rank \
WHERE dst(edge) == "team204" \
YIELD src(edge) AS src, dst(edge) AS dst, rank(edge) AS rank \
| DELETE EDGE follow $-.src->$-.dst @ $-.rank;
```
4 changes: 2 additions & 2 deletions docs-2.0/3.ngql-guide/3.data-types/6.list.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ nebula> RETURN size([1,2,3]);
+---------------+

# 将列表[92,90]中的元素做运算,然后在where子句中进行条件判断。
nebula> GO FROM "player100" OVER follow WHERE follow.degree NOT IN [x IN [92, 90] | x + $$.player.age] \
YIELD follow._dst AS id, follow.degree AS degree;
nebula> GO FROM "player100" OVER follow WHERE properties(edge).degree NOT IN [x IN [92, 90] | x + $$.player.age] \
YIELD dst(edge) AS id, properties(edge).degree AS degree;
+-------------+--------+
| id | degree |
+-------------+--------+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ Nebula Graph支持三种方式进行复合查询(或子查询):

```ngql
# 管道符连接多个查询。
nebula> GO FROM "player100" OVER follow YIELD follow._dst AS id | \
GO FROM $-.id OVER serve YIELD $$.team.name AS Team, \
$^.player.name AS Player;
+---------+-------------+
| Team | Player |
+---------+-------------+
| Nuggets | Tony Parker |
+---------+-------------+
nebula> GO FROM "player100" OVER follow YIELD dst(edge) AS id | \
GO FROM $-.id OVER serve YIELD properties($$).name AS Team, \
properties($^).name AS Player;
+-----------+-----------------+
| Team | Player |
+-----------+-----------------+
| "Spurs" | "Tony Parker" |
+-----------+-----------------+
| "Hornets" | "Tony Parker" |
+-----------+-----------------+
| "Spurs" | "Manu Ginobili" |
+-----------+-----------------+
```
Loading