UltipaDocs
Try Playground
  • Introduction
  • Terminologies
    • Reserved Words
    • Data Types
    • Alias
    • Operators
    • Expression
    • Filter
    • Prefix
    • Node and Edge Templates
    • Homologous and Heterologous Data
    • Clause Execution Times
    • Graphset
    • Schema
    • Property
    • Insert
    • Overwrite
    • Upsert
    • Update
    • Delete
    • Find Nodes
    • Find Edges
      • AB
      • Autonet
      • Spread
      • Path Template
      • K-Hop
      • K-Hop Template
    • Find Subgraphs
    • GROUP BY
    • ORDER BY
    • SKIP
    • LIMIT
    • WHERE
    • RETURN
    • WITH
    • UNCOLLECT
    • UNION
    • UNION ALL
    • CALL
    • BATCH
      • Schema Checker
      • Equal
      • Not Equal
      • Less Than
      • Greater Than
      • Less Than or Equal
      • Greater Than or Equal
      • Between
      • Between or Equal
      • Beong to
      • Not Belong To
      • CONTAINS | String
      • CONTAINS | Full-Text
      • Regular Match
      • IS NULL
      • IS NOT NULL
      • And
      • Or
      • Not
      • Exclusive OR
      • DISTINCT
      • toString()
      • toInteger()
      • toFloat()
      • toDouble()
      • toDecimal()
      • toSet()
      • castToRaw()
      • now()
      • dateAdd()
      • dateDiff()
      • year()
      • month()
      • day()
      • dayOfWeek()
      • dateFormat()
      • point()
      • distance()
      • pointInPolygon()
      • lower()
      • upper()
      • reverse()
      • startsWith()
      • endsWith()
      • JSON_decode()
      • JSON_merge()
      • trim()
      • ltrim()
      • rtrim()
      • left()
      • right()
      • substring()
      • replace()
      • split()
      • intersection()
      • difference()
      • listUnion()
      • size()
      • head()
      • reduce()
      • listContains()
      • append()
      • pi()
      • pow()
      • sqrt()
      • abs()
      • floor()
      • ceil()
      • round()
      • sin()
      • cos()
      • tan()
      • cot()
      • asin()
      • acos()
      • atan()
      • length()
      • pnodes()
      • pedges()
      • count()
      • sum()
      • max()
      • min()
      • avg()
      • stddev()
      • collect()
      • dedup()
      • CASE
      • table()
      • coalesce()
      • ifnull()
    • Acceleration
    • Index
    • Full-text
    • LTE
    • Real-time Process
    • Backend Task
    • Analytics Node
    • Server Statistics
    • Server Backup
    • Privilege
    • Policy
    • User
  • Trigger
  1. Docs
  2. /
  3. UQL
  4. /
  5. Find Paths

AB

Overview

The clause ab().src().dest().depth() retrieves paths between a single source node and a single destination node.

Syntax

Clause Alias: PATH type

Method
Param Type
Param Spec
Required
Description
Alias
src()Filter/YesThe conditions of the single source node; error occurs if multiple nodes are specifiedNODE
dest()Filter/YesThe conditions of the single destination node; error occurs if multiple nodes are specifiedNODE
depth()Range/YesDepth of the paths (N≥1):
depth(N): N edges
depth(:N): 1~N edges
depth(M:N): M~N edges (M≥0)
N/A
shortest()/ or @<schema>.<property>LTE-ed numeric edge propertyNoReturn the (weighted) shortest path. When an edge property (with non-negative values) is specified, edges without that property will not be considered

The shortest() method only supports depth(N), indicating the (weighted) shortest paths within N steps
N/A
node_filter()Filter/NoThe conditions that all intermediate nodes in the paths must satisfyN/A
edge_filter()Filter/NoThe conditions that all edges in the paths must satisfyN/A
path_ascend()@<schema>.<property>LTE-ed numeric edge propertyNoReturn paths where the specified property values ascend from source to destination (edges without the property will not be considered)N/A
path_descend()@<schema>.<property>LTE-ed numeric edge propertyNoReturn paths where the specified property values descend from source to destination (edges without the property will not be considered)N/A
direction()Stringleft, rightNoDirection of all edges in the pathsN/A
no_circle()//NoPaths with circles will not be returned

Exception: When src() and dest() specify the same node and that node does not appear in any intermediate position, the path will still be returned
N/A
limit()Integer≥-1NoNumber of results to return for each subquery, -1 signifies returning allN/A

Examples

Example Graph

Run these UQLs row by row in an empty graphset to create this graph:

UQL
create().edge_property(@default, "weight", int32)
insert().into(@default).nodes([{_id:"A", _uuid:1}, {_id:"B", _uuid:2}, {_id:"C", _uuid:3}, {_id:"D", _uuid:4}, {_id:"E", _uuid:5}, {_id:"F", _uuid:6}])
Click to expand

Filter Depth

Example: Find 3-step paths from A to E, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(3) as p
return p{*}
Result
A --1--> C <--4-- D <--5-- E

Example: Find 1~3-step paths from A to E, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3) as p
return p{*}
Result
A --3--> E
A --1--> C <--4-- D <--5-- E
A <--6-- B <--2-- E

Example: Find 2~3-step paths from A to E, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(2:3) as p
return p{*}
Result
A --1--> C <--4-- D <--5-- E
A <--6-- B <-2-- E

Non-weighted Shortest Path

Example: Find shortest paths from A to E within 3 steps, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(3)
  .shortest() as p
return p{*}
Result
A --3--> E

Weighted Shortest Path

Example: Find shortest paths from A to E within 3 steps, use @default.weight as weight, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(3)
  .shortest(@default.weight) as p
return p{*}
Result
A <--6-- B <--2-- E

Analysis: Porperty @default.weight should be loaded to engine (LTE).

Filter Intermediate Nodes

Example: Find 1~3-step paths from A to E and not passing D, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .node_filter({_id != "D"}) as p
return p{*}
Result
A --3--> E
A <--6-- B <--2-- E

Filter Edges

Example: Find 1~3-step paths from A to E where the weight of edge is greater than 1, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .edge_filter({weight > 1}) as p
return p{*}
Result
A --3--> E

Edge Property Ascend/Descend

Example: Find 1~3-step paths from A to E with property @default.weight ascending along the path, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .path_ascend(@default.weight) as p
return p{*}
Result
A --3--> E
A --1--> C <--4-- D <--5-- E

Analysis: Porperty @default.weight should be loaded to engine (LTE).

Example: Find 1~3-step paths from A to E with property @default.weight descending along the path, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .path_descend(@default.weight) as p
return p{*}
Result
A --3--> E
A <--6-- B <--2-- E

Analysis: Porperty @default.weight should be loaded to engine (LTE).

Filter Edge Direction

Example: Find 1~3-step paths from A to E with all edges right-pointing, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .direction(right) as p
return p{*}
Result
A --3--> E

Example: Find 1~3-step paths from A to E with all edges left-pointing, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3)
  .direction(left) as p
return p{*}
Result
A <--6-- B <--2-- E

Filter Circles

Example: Find 4-step paths from A to E that do not contain circle, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "C"}).depth(4).no_circle() as p
return p{*}
Result
A <--6-- B <--2-- E --3--> D --4--> C

Analysis: Paths with circle will be returned if not using no_circle():

Result
A --3--> E --2--> B --6--> A --1--> C
A <--6-- B <--2-- E --3--> D --4--> C
A <--6-- B <--2-- E <--3-- A --1--> C

limit()

Example: Find a 1~3-step path from A to E, carry all properties

UQL
ab().src({_id == "A"}).dest({_id == "E"}).depth(:3).limit(1) as p
return p{*}
Result
A <--6-- B <--2-- E