The ab().src().dest().depth() statement retrieves paths between two sets of nodes by pairing each node in src() with each node in dest() for pathfinding. If n nodes are specified by src() and m nodes by dest(), a total of n * m node pairs will be considered.
Syntaxab().src(<filter?>).dest(<filter?>).depth(<range>)
PATHMethod | Param | Description | Optional | Alias Type |
|---|---|---|---|---|
src() | <filter?> | The filtering condition enclosed in {}, or an alias to specify the set of nodes as traversal sources. If left blank, all nodes are targeted. | No | NODE |
dest() | <filter?> | The filtering condition enclosed in {}, or an alias to specify the set of nodes as traversal destinations. If left blank, all nodes are targeted. | No | NODE |
depth() | <range> | The number of steps to travese (N≥1):
| No | N/A |
shortest() | <weight?> | Leaves it blank to find unweighted shortest paths or specifies a numeric edge property in the format @<schema>.<property> to find weighted shortest paths. The property shouldn't have negative values, and edges without these properties are disregarded. Only supports depth(N) for the shortest paths within N steps. | Yes | N/A |
node_filter() | <filter?> | The filtering condition enclosed in {} for all intermediate nodes in the paths. If left blank, no restriction is applied. | Yes | N/A |
edge_filter() | <filter?> | The filtering condition enclosed in {} for edges in the paths. If left blank, no restriction is applied. | Yes | N/A |
path_ascend() | <property> | Specifies a numeric edge property in the format @<schema>.<property> to find paths where this property values ascend from src() to dest(); edges without these properties are disregarded. | Yes | N/A |
path_descend() | <property> | Specifies a numeric edge property in the format @<schema>.<property> to find paths where this property values descend from src() to dest(); edges without these properties are disregarded. | Yes | N/A |
direction() | <leftRight> | Specifies the direction of all edges in the paths, which can be left or right. | Yes | N/A |
no_circle() | / | Excludes paths that form circles. A path has circles when it has repeated nodes. An exception is when src() and dest() specify the same node and that node does not appear as an intermediate node, the corresponding paths will still be returned. | Yes | N/A |
limit() | <N> | Limits the number of paths (N≥-1) returned for each node pair; -1 includes all paths. | Yes | N/A |

To create the graph, execute each of the following UQL queries sequentially in an empty graphset:
UQLcreate().edge_property(@default, "weight", int32) insert().into(@default).nodes([{_id:"A"}, {_id:"B"}, {_id:"C"}, {_id:"D"}, {_id:"E"}, {_id:"F"}]) insert().into(@default).edges([{_from:"A", _to:"C", weight:1}, {_from:"E", _to:"B", weight:1}, {_from:"A", _to:"E", weight:4}, {_from:"D", _to:"C", weight:2}, {_from:"E", _to:"D", weight:3}, {_from:"B", _to:"A", weight:2}, {_from:"F", _to:"A", weight:4}])
To find paths within 3 steps between nodes A or C and nodes D or E:
UQLab().src({_id in ["A", "C"]}).dest({_id in ["D", "E"]}).depth(:3) as p return p
Result: p

To find paths with exact 3 steps between nodes A, C and nodes D, E:
UQLab().src({_id in ["A", "C"]}).dest({_id in ["D", "E"]}).depth(3) as p return p
Result: p

To find paths with 2 to 3 steps between nodes A, C and nodes D, E:
UQLab().src({_id in ["A", "C"]}).dest({_id in ["D", "E"]}).depth(2:3) as p return p
Result: p

To find the shortest paths within 5 steps between node A and node D:
UQLab().src({_id == "A"}).dest({_id == "D"}).depth(5).shortest() as p return p
Result: p

To find the shortest paths weighted by the property @default.weight within 5 steps between node A and node D, and compute the total weight of the paths:
UQLab().src({_id == "A"}).dest({_id == "D"}).depth(5).shortest(@default.weight) as p call { with p uncollect pedges(p) as edges return sum(edges.weight) as weights } return p, weights
Result:
| p | weights |
|---|---|
![]() | 3 |
To find paths within 5 steps between node F and nodes E without passing through node D:
UQLab().src({_id == "F"}).dest({_id == "E"}).depth(:5).node_filter({_id != "D"}) as p return p
Result: p

To find paths within 3 steps between node A and node E, where the property weight of each edge is greater than 1:
UQLab().src({_id == "A"}).dest({_id == "E"}).depth(:3).edge_filter({weight > 1}) as p return p
Result: p

To find paths within 3 steps between node A to node E, where the property @default.weight values ascend along the path:
UQLab().src({_id == "A"}).dest({_id == "E"}).depth(:3).path_ascend(@default.weight) as p return p
Result: p

To find paths within 3 steps between node A to node E, where the property @default.weight values descend along the path:
UQLab().src({_id == "A"}).dest({_id == "E"}).depth(:3).path_descend(@default.weight) as p return p
Result: p

To find paths within 2 to 4 steps between nodes A, C and node E with all edges pointing to the left:
UQLab().src({_id in ["A", "C"]}).dest({_id == "E"}).depth(2:3).direction(left) as p return p
Result: p

To find paths with exact 4 steps between node A and E without any circles:
UQLab().src({_id == "A"}).dest({_id == "C"}).depth(4).no_circle() as p return p
Result: p

Without the no_circle() method, three paths will be returned:
UQLab().src({_id == "A"}).dest({_id == "C"}).depth(4) as p return p
Result: p

To find paths within 3 steps between nodes A, C and node E, return only one path for each node pair:
UQLab().src({_id in ["A", "C"]}).dest({_id == "E"}).depth(:3).limit(1) as p return p{*}
Result: p

In this query, the ab() statement executes two times, each time using one record from n. With the OPTIONAL prefix, the query returns null if no result is found during execution:
UQLfind().nodes({_id in ["A","C"]}) as n optional ab().src(n).dest({_id == "D"}).depth(1) as p return p
Result: p

Without the prefix OPTIONAL, only one record is returned:
UQLfind().nodes({_id in ["A","C"]}) as n ab().src(n).dest({_id == "D"}).depth(1) as p return p
Result: p
