跳转至

FIND PATHGraph

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

语法Graph

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

<vertex_id_list> ::=
    [vertex_id [, vertex_id] ...]
  • SHORTEST:查找最短路径。
  • ALL:查找所有路径。
  • NOLOOP:查找非循环路径。
  • <vertex_id_list>:点ID列表.多个点用英文逗号(,)分隔。支持$-$var
  • <edge_type_list>:边类型列表.多个边类型用英文逗号(,)分隔。*表示所有边类型。
  • REVERSELY | BIDIRECTREVERSELY表示反向,BIDIRECT表示双向。
  • <N>:路径的最大跳数。默认值为5
  • <M>:指定返回的最大行数。

限制Graph

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

示例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 FROM "team204" TO "player100" OVER * REVERSELY;
+--------------------------------------------+
| path                                       |
+--------------------------------------------+
| <("team204")<-[:serve@0 {}]-("player100")> |
+--------------------------------------------+
nebula> FIND ALL PATH FROM "player100" TO "team204" OVER *;
+-------------------------------------------------------------------------------+
| path                                                                          |
+-------------------------------------------------------------------------------+
| <("player100")-[:serve@0 {}]->("team204")>                                    |
+-------------------------------------------------------------------------------+
| <("player100")-[:follow@0 {}]->("player125")-[: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子句,因此不能在遍历过程中进行条件过滤。


最后更新: 2021年6月17日
Back to top