FIND PATH¶
The FIND PATH
statement finds the paths between the selected source vertices and destination vertices.
Note
To improve the query performance with the FIND PATH
statement, you can add the num_operator_threads
parameter in the nebula-graphd.conf
configuration file. The value range of the num_operator_threads
parameter is [2, 10] and make sure that the value is not greater than the number of CPU cores of the machine where the graphd
service is deployed. It is recommended to set the value to the number of CPU cores of the machine where the graphd
service is deployed. For more information about the nebula-graphd.conf
configuration file, see nebula-graphd.conf.
Syntax¶
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> {STEP|STEPS}]
YIELD path as <alias>
[| ORDER BY $-.path] [| LIMIT <M>];
<vertex_id_list> ::=
[vertex_id [, vertex_id] ...]
SHORTEST
finds all the shortest path.
ALL
finds all the paths.
NOLOOP
finds the paths without circles.
WITH PROP
shows properties of vertices and edges. If not specified, properties will be hidden.
<vertex_id_list>
is a list of vertex IDs separated with commas (,). It supports$-
and$var
.
<edge_type_list>
is a list of edge types separated with commas (,).*
is all edge types.
REVERSELY | BIDIRECT
specifies the direction.REVERSELY
is reverse graph traversal whileBIDIRECT
is bidirectional graph traversal.
<WHERE clause>
filters properties of edges.
UPTO <N> {STEP|STEPS}
is the maximum hop number of the path. The default value is5
.
ORDER BY $-.path
specifies the order of the returned paths. For information about the order rules, see Path.
LIMIT <M>
specifies the maximum number of rows to return.
Note
The path type of FIND PATH
is trail
. Only vertices can be repeatedly visited in graph traversal. For more information, see Path.
Limitations¶
- When a list of source and/or destination vertex IDs are specified, the paths between any source vertices and the destination vertices will be returned.
- There can be cycles when searching all paths.
FIND PATH
only supports filtering properties of edges withWHERE
clauses. Filtering properties of vertices and functions are not supported for now.
FIND PATH
is a single-thread procedure, so it uses much memory.
Examples¶
A returned path is like (<vertex_id>)-[:<edge_type_name>@<rank>]->(<vertex_id)
.
nebula> FIND SHORTEST PATH FROM "player102" TO "team204" OVER * YIELD path AS p;
+--------------------------------------------+
| p |
+--------------------------------------------+
| <("player102")-[:serve@0 {}]->("team204")> |
+--------------------------------------------+
nebula> FIND SHORTEST PATH WITH PROP FROM "team204" TO "player100" OVER * REVERSELY YIELD path AS p;
+--------------------------------------------------------------------------------------------------------------------------------------+
| p |
+--------------------------------------------------------------------------------------------------------------------------------------+
| <("team204" :team{name: "Spurs"})<-[:serve@0 {end_year: 2016, start_year: 1997}]-("player100" :player{age: 42, name: "Tim Duncan"})> |
+--------------------------------------------------------------------------------------------------------------------------------------+
nebula> FIND SHORTEST PATH FROM "player100", "player130" TO "player132", "player133" OVER * BIDIRECT UPTO 18 STEPS YIELD path as p;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| p |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| <("player100")<-[:follow@0 {}]-("player144")<-[:follow@0 {}]-("player133")> |
| <("player100")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player109")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player104")-[:serve@20182019 {}]->("team204")<-[:serve@0 {}]-("player114")<-[:follow@0 {}]-("player133")> |
| ... |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player112")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| <("player130")-[:serve@0 {}]->("team219")<-[:serve@0 {}]-("player109")-[:serve@0 {}]->("team204")<-[:serve@0 {}]-("player138")-[:serve@0 {}]->("team225")<-[:serve@0 {}]-("player132")> |
| ... |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
nebula> FIND ALL PATH FROM "player100" TO "team204" OVER * WHERE follow.degree is EMPTY or follow.degree >=0 YIELD path AS p;
+------------------------------------------------------------------------------+
| p |
+------------------------------------------------------------------------------+
| <("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 * YIELD path AS p;
+--------------------------------------------------------------------------------------------------------+
| p |
+--------------------------------------------------------------------------------------------------------+
| <("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")> |
+--------------------------------------------------------------------------------------------------------+
FAQ¶
Does it support the WHERE clause to achieve conditional filtering during graph traversal?¶
FIND PATH
only supports filtering properties of edges with WHERE
clauses, such as WHERE follow.degree is EMPTY or follow.degree >=0
.
Filtering properties of vertices is not supported for now.