FIND PATH

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

语法

  1. FIND { SHORTEST | ALL | NOLOOP } PATH FROM <vertex_id_list> TO <vertex_id_list>
  2. OVER <edge_type_list> [REVERSELY | BIDIRECT] [UPTO <N> STEPS] [| ORDER BY $-.path] [| LIMIT <M>];
  3. <vertex_id_list> ::=
  4. [vertex_id [, vertex_id] ...]
  • SHORTEST:查找最短路径。

  • ALL:查找所有路径。

  • NOLOOP:查找非循环路径。

  • <vertex_id_list>:点ID列表.多个点用英文逗号(,)分隔。支持$-$var

  • <edge_type_list>:边类型列表.多个边类型用英文逗号(,)分隔。*表示所有边类型。

  • REVERSELY | BIDIRECTREVERSELY表示反向,BIDIRECT表示双向。

  • <N>:路径的最大跳数。默认值为5

  • <M>:指定返回的最大行数。

限制

  • 指定起始点和目的点的列表后,会返回起始点和目的点所有组合的路径。

  • 搜索所有路径时可能会出现循环。

  • 不支持过滤属性。

  • 路径的查找是单线程,会占用很多内存。

示例

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

  1. nebula> FIND SHORTEST PATH FROM "player102" TO "team204" OVER *;
  2. +--------------------------------------------+
  3. | path |
  4. +--------------------------------------------+
  5. | <("player102")-[:serve@0 {}]->("team204")> |
  6. +--------------------------------------------+
  1. nebula> FIND SHORTEST PATH FROM "team204" TO "player100" OVER * REVERSELY;
  2. +--------------------------------------------+
  3. | path |
  4. +--------------------------------------------+
  5. | <("team204")<-[:serve@0 {}]-("player100")> |
  6. +--------------------------------------------+
  1. nebula> FIND ALL PATH FROM "player100" TO "team204" OVER *;
  2. +-------------------------------------------------------------------------------+
  3. | path |
  4. +-------------------------------------------------------------------------------+
  5. | <("player100")-[:serve@0 {}]->("team204")> |
  6. +-------------------------------------------------------------------------------+
  7. | <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")> |
  8. +-------------------------------------------------------------------------------+
  9. ...
  1. nebula> FIND NOLOOP PATH FROM "player100" TO "team204" OVER *;
  2. +--------------------------------------------------------------------------------------------------------+
  3. | path |
  4. +--------------------------------------------------------------------------------------------------------+
  5. | <("player100")-[:serve@0 {}]->("team204")> |
  6. +--------------------------------------------------------------------------------------------------------+
  7. | <("player100")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")> |
  8. +--------------------------------------------------------------------------------------------------------+
  9. | <("player100")-[:follow@0 {}]->("player101")-[:serve@0 {}]->("team204")> |
  10. +--------------------------------------------------------------------------------------------------------+
  11. | <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player125")-[:serve@0 {}]->("team204")> |
  12. +--------------------------------------------------------------------------------------------------------+
  13. | <("player100")-[:follow@0 {}]->("player101")-[:follow@0 {}]->("player102")-[:serve@0 {}]->("team204")> |
  14. +--------------------------------------------------------------------------------------------------------+

FAQ

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

不支持WHERE子句,因此不能在遍历过程中进行条件过滤。