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

add go format #1064

Merged
merged 3 commits into from
Oct 18, 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
2 changes: 2 additions & 0 deletions docs-2.0/3.ngql-guide/6.functions-and-expressions/4.schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Nebula Graph支持以下Schema函数。
|list labels(vertex) | 返回点的Tag,与tags()作用相同,用于兼容openCypher语法。|
|map properties(vertex_or_edge) | 接收点或边并返回其属性。|
|string type(edge) | 返回边的Edge type。|
|src(edge)|返回边的起始点ID。数据类型和点ID的类型保持一致。|
|dst(edge)|返回边的目的点ID。数据类型和点ID的类型保持一致。|
|vertex startNode(path) | 获取一条边或一条路径并返回它的起始点ID。|
|string endNode(path) | 获取一条边或一条路径并返回它的目的点ID。|
|int rank(edge) | 返回边的rank。|
Expand Down
67 changes: 32 additions & 35 deletions docs-2.0/3.ngql-guide/7.general-query-statements/3.go.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ GO [[<M> TO] <N> STEPS ] FROM <vertex_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>]

GO [[<M> TO] <N> STEPS ] FROM <vertex_list>
OVER <edge_type_list> [{REVERSELY | BIDIRECT}]
[ WHERE <conditions> ]
[| GROUP BY {col_name | expr | position} YIELD <col_name>]

<vertex_list> ::=
<vid> [, <vid> ...]

Expand Down Expand Up @@ -52,7 +48,9 @@ OVER <edge_type_list> [{REVERSELY | BIDIRECT}]

遍历多个Edge type时,`WHERE`子句有一些限制。例如不支持`WHERE edge1.prop1 > edge2.prop2`。

- `YIELD [DISTINCT] <return_list>`:指定输出结果。详情请参见[YIELD](../8.clauses-and-options/yield.md)。如果没有指定,默认返回目的点ID。
- `YIELD [DISTINCT] <return_list>`:定义需要返回的输出。` <return_list>`建议使用[Schema函数](../6.functions-and-expressions/4.schema.md),当前支持`src(edge)`、`dst(edge)`、`type(edge)`、`rank(edge)`、`properties(edge)`、`id(vertex)`、`properties(vertex)`。详情请参见[YIELD](../8.clauses-and-options/yield.md)。如果没有指定,默认返回目的点ID。

- `GROUP BY`:根据指定属性的值将输出分组。详情请参见[GROUP BY](../8.clauses-and-options/group-by.md)。分组后需要再次使用`YIELD`定义需要返回的输出。

- `ORDER BY`:指定输出结果的排序规则。详情请参见[ORDER BY](../8.clauses-and-options/order-by.md)。

Expand All @@ -62,8 +60,6 @@ OVER <edge_type_list> [{REVERSELY | BIDIRECT}]

- `LIMIT`:限制输出结果的行数。详情请参见[LIMIT](../8.clauses-and-options/limit.md)。

- `GROUP BY`:根据指定属性的值将输出分组。详情请参见[GROUP BY](../8.clauses-and-options/group-by.md)。

## 示例

```ngql
Expand Down Expand Up @@ -94,8 +90,9 @@ nebula> GO 2 STEPS FROM "player102" OVER follow;
```ngql
# 添加过滤条件。
nebula> GO FROM "player100", "player102" OVER serve \
WHERE serve.start_year > 1995 \
YIELD DISTINCT $$.team.name AS team_name, serve.start_year AS start_year, $^.player.name AS player_name;
WHERE properties(edge).start_year > 1995 \
YIELD DISTINCT properties($$).name AS team_name, properties(edge).start_year AS start_year, properties($^).name AS player_name;

+-----------------+------------+---------------------+
| team_name | start_year | player_name |
+-----------------+------------+---------------------+
Expand All @@ -108,24 +105,24 @@ nebula> GO FROM "player100", "player102" OVER serve \
```

```ngql
# 遍历多个Edge type。属性没有值时,会显示__EMPTY__
# 遍历多个Edge type。属性没有值时,会显示UNKNOWN_PROP
nebula> GO FROM "player100" OVER follow, serve \
YIELD follow.degree, serve.start_year;
+---------------+------------------+
| follow.degree | serve.start_year |
+---------------+------------------+
| 95 | __EMPTY__ |
+---------------+------------------+
| 95 | __EMPTY__ |
+---------------+------------------+
| __EMPTY__ | 1997 |
+---------------+------------------+
YIELD properties(edge).degree, properties(edge).start_year;
+-------------------------+-----------------------------+
| properties(EDGE).degree | properties(EDGE).start_year |
+-------------------------+-----------------------------+
| 95 | UNKNOWN_PROP |
+-------------------------+-----------------------------+
| 95 | UNKNOWN_PROP |
+-------------------------+-----------------------------+
| UNKNOWN_PROP | 1997 |
+-------------------------+-----------------------------+
```

```ngql
# 返回player100入方向的邻居点。
nebula> GO FROM "player100" OVER follow REVERSELY \
YIELD follow._dst AS destination;
YIELD src(edge) AS destination;
+-------------+
| destination |
+-------------+
Expand All @@ -151,16 +148,16 @@ nebula> MATCH (v)<-[e:follow]- (v2) WHERE id(v) == 'player100' \
```ngql
# 查询player100的朋友和朋友所属队伍。
nebula> 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;
+---------------------+-----------------+
| FriendOf | Team |
+---------------------+-----------------+
| "Tony Parker" | "Spurs" |
| "Danny Green" | "Spurs" |
+---------------------+-----------------+
| "Tony Parker" | "Hornets" |
| "Danny Green" | "Cavaliers" |
+---------------------+-----------------+
...

Expand All @@ -180,8 +177,8 @@ nebula> MATCH (v)<-[e:follow]- (v2)-[e2:serve]->(v3) \

```ngql
# 返回player102所有邻居点。
nebula> GO FROM "player102" OVER follow BIDIRECT \
YIELD follow._dst AS both;
nebula> GO FROM "player102" OVER follow \
YIELD dst(edge) AS both;
+-------------+
| both |
+-------------+
Expand All @@ -208,7 +205,7 @@ nebula> MATCH (v) -[e:follow]-(v2) \
```ngql
# 查询player100 1~2跳内的朋友。
nebula> GO 1 TO 2 STEPS FROM "player100" OVER follow \
YIELD follow._dst AS destination;
YIELD dst(edge) AS destination;
+-------------+
| destination |
+-------------+
Expand All @@ -234,9 +231,9 @@ nebula> MATCH (v) -[e:follow*1..2]->(v2) \
```ngql
# 根据年龄分组。
nebula> GO 2 STEPS FROM "player100" OVER follow \
YIELD follow._src AS src, follow._dst AS dst, $$.player.age AS age \
YIELD src(edge) AS src, dst(edge) AS dst, properties($$).age AS age \
| GROUP BY $-.dst \
YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age
YIELD $-.dst AS dst, collect_set($-.src) AS src, collect($-.age) AS age;
+-------------+----------------------------+----------+
| dst | src | age |
+-------------+----------------------------+----------+
Expand All @@ -250,9 +247,9 @@ nebula> GO 2 STEPS FROM "player100" OVER follow \

```ngql
# 分组并限制输出结果的行数。
nebula> $a = GO FROM "player100" OVER follow YIELD follow._src AS src, follow._dst AS dst; \
nebula> $a = GO FROM "player100" OVER follow YIELD src(edge) AS src, dst(edge) AS dst; \
GO 2 STEPS FROM $a.dst OVER follow \
YIELD $a.src AS src, $a.dst, follow._src, follow._dst \
YIELD $a.src AS src, $a.dst, src(edge), dst(edge) \
| ORDER BY $-.src | OFFSET 1 LIMIT 2;
+-------------+-------------+-------------+-------------+
| src | $a.dst | follow._src | follow._dst |
Expand All @@ -265,7 +262,7 @@ nebula> $a = GO FROM "player100" OVER follow YIELD follow._src AS src, follow._d

```ngql
# 在多个边上通过IS NOT EMPTY进行判断。
nebula> GO FROM "player100" OVER * WHERE $$.player.name IS NOT EMPTY YIELD follow._dst;
nebula> GO FROM "player100" OVER follow WHERE properties($$).name IS NOT EMPTY YIELD dst(edge);
+-------------+
| follow._dst |
+-------------+
Expand Down
18 changes: 9 additions & 9 deletions docs-2.0/3.ngql-guide/8.clauses-and-options/yield.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

!!! note
下文示例中的`$$`、`$-`等是引用符号,详情请参见[引用符](../5.operators/5.property-reference.md)。

## YIELD子句

### 语法
Expand All @@ -45,7 +45,7 @@ YIELD [DISTINCT] <col> [AS <alias>] [, <col> [AS <alias>] ...];

```ngql
nebula> GO FROM "player100" OVER follow \
YIELD $$.player.name AS Friend, $$.player.age AS Age;
YIELD properties($$).name AS Friend, properties($$).age AS Age;
+-----------------+-----+
| Friend | Age |
+-----------------+-----+
Expand All @@ -72,11 +72,11 @@ YIELD [DISTINCT] <col> [AS <alias>] [, <col> [AS <alias>] ...];
```ngql
nebula> LOOKUP ON player WHERE player.name == "Tony Parker" \
YIELD player.name, player.age;
=======================================
| VertexID | player.name | player.age |
=======================================
| 101 | Tony Parker | 36 |
---------------------------------------
+-------------+---------------+------------+
| VertexID | player.name | player.age |
+-------------+---------------+------------+
| "player101" | "Tony Parker" | 36 |
+-------------+---------------+------------+
```

## YIELD语句
Expand All @@ -102,7 +102,7 @@ YIELD [DISTINCT] <col> [AS <alias>] [, <col> [AS <alias>] ...]
```ngql
# 查找player100关注的player,并计算他们的平均年龄。
nebula> GO FROM "player100" OVER follow \
YIELD follow._dst AS ID \
YIELD dst(edge) AS ID \
| FETCH PROP ON player $-.ID \
YIELD player.age AS Age \
| YIELD AVG($-.Age) as Avg_age, count(*)as Num_friends;
Expand All @@ -116,7 +116,7 @@ nebula> GO FROM "player100" OVER follow \
```ngql
# 查找player101关注的player,返回degree大于90的player。
nebula> $var1 = GO FROM "player101" OVER follow \
YIELD follow.degree AS Degree, follow._dst as ID; \
YIELD properties(edge).degree AS Degree, dst(edge) as ID; \
YIELD $var1.ID AS ID WHERE $var1.Degree > 90;
+-------------+
| ID |
Expand Down