FIND PATH

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

语法

  1. FIND { SHORTEST | ALL | NOLOOP } PATH [WITH PROP] FROM <vertex_id_list> TO <vertex_id_list>
  2. OVER <edge_type_list> [REVERSELY | BIDIRECT] [<WHERE clause>] [UPTO <N> STEPS] [| ORDER BY $-.path] [| LIMIT <M>];
  3. <vertex_id_list> ::=
  4. [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>:指定返回的最大行数。

限制

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

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

  • 使用WHERE子句时只能过滤边属性,暂不支持过滤点属性,且不支持函数。

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

示例

返回的路径格式类似于(<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 WITH PROP FROM "team204" TO "player100" OVER * REVERSELY;
  2. +--------------------------------------------------------------------------------------------------------------------------------------+
  3. | path |
  4. +--------------------------------------------------------------------------------------------------------------------------------------+
  5. | <("team204" :team{name: "Spurs"})<-[:serve@0 {end_year: 2016, start_year: 1997}]-("player100" :player{age: 42, name: "Tim Duncan"})> |
  6. +--------------------------------------------------------------------------------------------------------------------------------------+
  1. nebula> FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0;
  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. ...
  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子句过滤,但目前只能过滤边属性,如示例中的FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0;

暂不支持过滤点属性。