跳转至

FIND PATHGraph

FIND PATH语句查找指定起始点和目的点之间的路径。

语法Graph

FIND { SHORTEST | ALL | NOLOOP } PATH [WITH PROP] FROM <vertex_id_list> TO <vertex_id_list>
OVER <edge_type_list> [REVERSELY | BIDIRECT] [<WHERE clause>] [UPTO <N> STEPS] [| ORDER BY $-.path] [| LIMIT <M>];

<vertex_id_list> ::=
    [vertex_id [, vertex_id] ...]
  • SHORTEST:查找最短路径。
  • ALL:查找所有路径。
  • NOLOOP:查找非循环路径。
  • WITH PROP:展示点和边的属性。不添加本参数则隐藏属性。
  • <vertex_id_list>:点ID列表。多个点用英文逗号(,)分隔。支持$-$var
  • <edge_type_list>:Edge type列表。多个Edge type用英文逗号(,)分隔。*表示所有Edge type。
  • REVERSELY | BIDIRECTREVERSELY表示反向,BIDIRECT表示双向。
  • <WHERE clause>:可以使用WHERE子句过滤边属性。
  • <N>:路径的最大跳数。默认值为5
  • <M>:指定返回的最大行数。

Note

FIND PATH语句检索的路径类型为trail,即检索的路径只有点可以重复,边不可以重复。详情请参见Graph。

限制Graph

  • 指定起始点和目的点的列表后,会返回起始点和目的点所有组合的路径。
  • 搜索所有路径时可能会出现循环。
  • 使用WHERE子句时只能过滤边属性,暂不支持过滤点属性,且不支持函数。
  • 路径的查找是单进程,会占用很多内存。

示例Graph

返回的路径格式类似于(<vertex_id>)-[:<edge_type_name>@<rank>]->(<vertex_id)

nebula> FIND SHORTEST PATH FROM "player102" TO "team204" OVER *;
+--------------------------------------------+
| path                                       |
+--------------------------------------------+
| <("player102")-[:serve@0 {}]->("team204")> |
+--------------------------------------------+
nebula> FIND SHORTEST PATH WITH PROP FROM "team204" TO "player100" OVER * REVERSELY;
+--------------------------------------------------------------------------------------------------------------------------------------+
| path                                                                                                                                 |
+--------------------------------------------------------------------------------------------------------------------------------------+
| <("team204" :team{name: "Spurs"})<-[:serve@0 {end_year: 2016, start_year: 1997}]-("player100" :player{age: 42, name: "Tim Duncan"})> |
+--------------------------------------------------------------------------------------------------------------------------------------+
nebula> FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0;
+------------------------------------------------------------------------------+
| path                                                                         |
+------------------------------------------------------------------------------+
| <("player100")-[:serve@0 {}]->("team204")>                                   |
| <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")>     |
| <("player100")-[:follow@0 {}]->("player101")-[:serve@0 {}]->("team204")>     |
| ...                                                                          |
+------------------------------------------------------------------------------+
nebula> FIND NOLOOP PATH FROM "player100" TO "team204" OVER *;
+--------------------------------------------------------------------------------------------------------+
| path                                                                                                   |
+--------------------------------------------------------------------------------------------------------+
| <("player100")-[:serve@0 {}]->("team204")>                                                             |
| <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")>                               |
| <("player100")-[:follow@0 {}]->("player101")-[:serve@0 {}]->("team204")>                               |
| <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")> |
| <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player102")-[:serve@0 {}]->("team204")> |
| ...                                                                                                    |
+--------------------------------------------------------------------------------------------------------+

FAQGraph

是否支持WHERE子句,以实现图遍历过程中的条件过滤?Graph

支持使用WHERE子句过滤,但目前只能过滤边属性,如示例中的FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0;

暂不支持过滤点属性。


最后更新: November 1, 2021
Back to top