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

Spread

The spread().src().depth() query can find and return edges from a start node within K hops, by specifying k-index, applying filters on the initial-node, all edges and all neighbor nodes. The found edges are returned from shallower to deeper, in form of 1-step paths (start node, edge, end node).

NOTE

Spread is a BFS (Breadth First Search) query method that is commonly used in graph query/analysis industry for observing layers of relationship around an entity, and to retrieve and acquire data quickly.

Syntax:

  • Statement alias: supported (PATH)
  • All parameters:
ParameterTypeSpecificationDescriptionStructure of Custom Alias
src()FilterMandatoryThe filtering rules of the start node; error will occur if multiple nodes are foundNODE
depth()Int>0; mandatoryThe maximum depth to spreadNot supported
node_filter()FilterThe filtering rules that neighbor nodes other than src need to satisfyNot supported
edge_filter()FilterThe filtering rules that all edges need to satisfyNot supported
direction()Stringleft, rightTo specify the direction of the edgeNot supported
limit()Int-1 or >=0Number of results to return for each subquery, -1 means to return all resultsNot supported

Sample graph: (to be used for the following examples)

(All nodes and edges are of schema @default)
Run below UQLs one by one in an empty graphset to create graph data: ```customlang___fold__lang_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}]) insert().into(@default).edges([{_uuid:1, _from_uuid:1, _to_uuid:3, weight:1}, {_uuid:2, _from_uuid:5, _to_uuid:2 , weight:1}, {_uuid:3, _from_uuid:1, _to_uuid:5 , weight:4}, {_uuid:4, _from_uuid:4, _to_uuid:3 , weight:2}, {_uuid:5, _from_uuid:5, _to_uuid:4 , weight:3}, {_uuid:6, _from_uuid:2, _to_uuid:1 , weight:2}, {_uuid:7, _from_uuid:6, _to_uuid:1 , weight:4}]) ```

Filter Depth

Find 1~2-Hop edges of node D, return as paths and carry all properties

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

Analysis: Both the start node and end node of edge 6 are from 2-Hop of node D, edge 6 is also considered as from 2-Hop of node D.

Filter Neighbor Nodes

Example: Find 1~2-Hop edges of node D, whose shortest path does not pass node E, return as paths and carry all properties

UQL
spread().src({_id == "D"}).depth(2)
  .node_filter({_id != "E"}) as e
return e{*}
Result
A --1--> C
D --4--> C

Analysis: When the shortest path are not allowed to pass node E, it is equivalent to removing node E and its adjacent edges 2, 3 and 5 from the graph, in which case edge 6 is from 3-Hop of node D and not presents in the result.

Filter Edges

Example: Find 1~2-Hop edges of node D, whose shortest path does not pass edge 5, return as paths and carry all properties

UQL
spread().src({_id == "D"}).depth(2)
  .edge_filter({_uuid != 5}) as e
return e{*}
Result
A --1--> C
D --4--> C

Analysis: When the shortest path are not allowed to pass edge 5, it is equivalent to removing edge 5 from the graph, in which case edge 3 and 6 are from 3-Hop of node D, edge 2 is from 4-Hop of node D.

Filter Edge Direction

Example: Find 1~2-Hop edges of node D, with all edges right-pointing, return as paths and carry all properties

UQL
spread().src({_id == "D"}).depth(2)
  .direction(right) as e
return e{*}
Result
D --4--> C

When all edges in the shortest path are right-pointing (outbound), node D has only one 1-Hop edge 4, and has no edge from 2-Hop or deeper since the end node of edge 4 has no outbound edge.

Example: Find 1~2-Hop edges of node D, with all edges left-pointing, return as paths and carry all properties

UQL
spread().src({_id == "D"}).depth(2)
  .direction(left) as e
return e{*}
Result
E --5--> D
A --3--> E

Analysis: When all edges in the shortest path are left-pointing (inbound), node D has a 1-Hop edge 5 and a 2-Hop edge 3.

Limit Result of Sub-Query

Example: Find three 1~3-Hop edges of node D, return as paths and carry all properties

UQL
spread().src({_id == "D"}).depth(3).limit(3) as e
return e{*}
Result
E --5--> D
A --3--> E
D --4--> C