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

modify maxHop #1661

Merged
merged 1 commit into from
Apr 19, 2022
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: 1 addition & 1 deletion docs-2.0/2.quick-start/6.cheatsheet-for-ngql-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
| 匹配多个 Edge type | `MATCH (v:player{name:"Tim Duncan"})-[e:follow | :serve]->(v2) RETURN e` | 使用`|`可以匹配多个 Edge type,例如`[e:follow | :serve]`。第一个 Edge type 前的英文冒号(:)不可省略,后续 Edge type 前的英文冒号可以省略,例如`[e:follow | serve]`。 |
| 匹配多条边 | `MATCH (v:player{name:"Tim Duncan"})-[]->(v2)<-[e:serve]-(v3) RETURN v2, v3` | 用户可以扩展模式,匹配路径中的多条边。 |
| 匹配定长路径 | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*2]->(v2) RETURN DISTINCT v2 AS Friends` | 用户可以在模式中使用`:<edge_type>*<hop>`匹配定长路径。`hop`必须是一个非负整数。`e`的数据类型是列表。 |
| 匹配变长路径 | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*1..3]->(v2) RETURN v2 AS Friends` | `minHop`:可选项。表示路径的最小长度。`minHop`必须是一个非负整数,默认值为 1。<br>`maxHop`:必选项。表示路径的最大长度。`maxHop`必须是一个非负整数,没有默认值。`e`的数据类型是列表。 |
| 匹配变长路径 | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*1..3]->(v2) RETURN v2 AS Friends` | `minHop`:可选项。表示路径的最小长度。`minHop`必须是一个非负整数,默认值为 1。<br>`maxHop`:可选项。表示路径的最大长度。`maxHop`必须是一个非负整数,默认为无穷大。`e`的数据类型是列表。 |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not good...

| 匹配多个 Edge type 的变长路径 | `MATCH p=(v:player{name:"Tim Duncan"})-[e:follow | serve*2]->(v2) RETURN DISTINCT v2` | 用户可以在变长或定长模式中指定多个 Edge type。`hop`、`minHop`和`maxHop`对所有 Edge type 都生效。`e`的数据类型是列表。|
| 检索点或边的信息 | `MATCH (v:player{name:"Tim Duncan"}) RETURN v`<br>`MATCH (v:player{name:"Tim Duncan"})-[e]->(v2) RETURN e` | 使用`RETURN {<vertex_name> | <edge_name>}`检索点或边的所有信息。 |
| 检索点 ID | `MATCH (v:player{name:"Tim Duncan"}) RETURN id(v)` | 使用`id()`函数检索点 ID。 |
Expand Down
36 changes: 30 additions & 6 deletions docs-2.0/3.ngql-guide/7.general-query-statements/2.match.md
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,31 @@ nebula> MATCH (v:player{name:"Tim Duncan"}) -[*0]-> (v2) \

### 匹配变长路径

用户可以在模式中使用`:<edge_type>*[minHop]..[maxHop]`匹配变长路径。
用户可以在模式中使用`:<edge_type>*[minHop..maxHop]`匹配变长路径。

!!! note

设置边界时,`minHop` 和 `maxHop` 至少存在其中一个。

!!! caution

如果未设置 `maxHop` 可能会导致 graph 服务 OOM,请谨慎执行该命令。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


|参数|说明|
|:---|:---|
|`minHop`|可选项。表示路径的最小长度。`minHop`必须是一个非负整数,默认值为 1。|
|`maxHop`|可选项。表示路径的最大长度。`maxHop`必须是一个非负整数,没有默认值。|

!!! compatibility "openCypher 兼容性"

在 openCypher 中,没有设置`maxHop`时,`..`可以省略。在 nGQL 中,`..`不可以省略。
|`maxHop`|可选项。表示路径的最大长度。`maxHop`必须是一个非负整数,默认值为无穷大。|

```ngql
nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*]->(v2) \
RETURN v2 AS Friends;
+-----------------------------------------------------------+
| Friends |
+-----------------------------------------------------------+
| ("player125" :player{age: 41, name: "Manu Ginobili"}) |
| ("player101" :player{age: 36, name: "Tony Parker"}) |
...

nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*1..3]->(v2) \
RETURN v2 AS Friends;
+-----------------------------------------------------------+
Expand All @@ -474,6 +487,17 @@ nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*1..3]->(v2) \
| ("player125" :player{age: 41, name: "Manu Ginobili"}) |
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
...

nebula> MATCH p=(v:player{name:"Tim Duncan"})-[e:follow*1..]->(v2) \
RETURN v2 AS Friends;
Comment on lines +491 to +492
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果用户没注意前面的caution,直接拿这个例子去改,可能会oom。所以我们是不是考虑不要放这个例子?

+-----------------------------------------------------------+
| Friends |
+-----------------------------------------------------------+
| ("player125" :player{age: 41, name: "Manu Ginobili"}) |
| ("player101" :player{age: 36, name: "Tony Parker"}) |
| ("player100" :player{age: 42, name: "Tim Duncan"}) |
...

```

用户可以使用`DISTINCT`关键字聚合重复结果。
Expand Down