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. Queries

RETURN

RETURN performs functional operations on the alias, and assembles multiple return values to send back to client end. Return values that are heterologous will NOT be trimmed.

Syntax: RETURN <expression> as <alias>, <expression> as <alias>, ...
Input:

  • <expression>: Return value
  • <alias>: Alias of return value, optional

RETURN clause is usually the last statement of a UQL, but can also be followed by ORDER BY, LIMIT or SKIP. Deduplicating an alias in RETURN clause will not affect its homologous aliases.

For instance, assemble 3 return values, of which n1 is heterologous with the other two; the deduplication against n2.color does NOT affect pnodes(path), which is homologous with n2.color:

UQL
find().nodes() as n1 limit 5
n(3).e()[2].n(as n2) as path
return n1, pnodes(path), dedup(n2.color)
NOTE

For information on how to designate properties to be carried by NODE, EDGE, or PATH in RETURN clause, please refer to Chapter Query - Alias System.

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

Run below UQLs one by one in an empty graphset to create graph data: ```customlang___fold__lang_uql create().node_schema("account").node_schema("movie").edge_schema("rate").edge_schema("wishlist") create().node_property(@*, "name").node_property(@account, "age", int32).node_property(@movie, "year", int32).edge_property(@rate, "score", int32) insert().into(@account).nodes([{_id:"S001", _uuid:1, name:"Pepe", age:24}, {_id:"S002", _uuid:2, name:"Lina", age:23}, {_id:"S003", _uuid:3, name:"Emma", age:26}]) insert().into(@movie).nodes([{_id:"M001", _uuid:4, name:"Léon", year:1994}, {_id:"M002", _uuid:5, name:"Avatar", year:2009}]) insert().into(@rate).edges([{_uuid:1, _from_uuid:1, _to_uuid:4, score:9}, {_uuid:2, _from_uuid:3, _to_uuid:5, score:8}]) insert().into(@wishlist).edges([{_uuid:3, _from_uuid:2, _to_uuid:4}, {_uuid:4, _from_uuid:3, _to_uuid:4}]) ```

Return NODE

Example: Carry all properties

UQL
find().nodes({@account}) as n
return n{*} 
Result
|-------- @account ---------|
| _id  | _uuid | name | age |
|------|-------|------|-----|
| S001 | 1     | Pepe | 24  |
| S002 | 2     | Lina | 23  |
| S003 | 3     | Emma | 26  |

Example: Carry some custom properties

UQL
find().nodes() as n
return n{name, year} 
Result
|------ @account -----|
| _id  | _uuid | name |
|------|-------|------|
| S001 | 1     | Pepe |
| S002 | 2     | Lina |
| S003 | 3     | Emma |

|----------- @movie -----------|
| _id  | _uuid |  name  | year |
|------|-------|--------|------|
| M001 | 4     | Léon   | 1994 |
| M002 | 5     | Avatar | 2009 |

Analysis: NODE only carries the properties that it has.

Example: Carry only system properties

UQL
find().nodes({@movie}) as n
return n 
Result
|--- @movie ---|
| _id  | _uuid |
|------|-------|
| M001 | 4     |
| M002 | 5     |

Return EDGE

Example: Carry all properties

UQL
find().edges({@rate}) as e
return e{*} 
Result
|------------------------ @rate -----------------------|
| _uuid | _from | _to  | _from_uuid | _to_uuid | score |
|-------|-------|------|------------|----------|-------|
|   1   | S001  | M001 | 1          | 4        | 9     |
|   2   | S003  | M002 | 3          | 5        | 8     |

Example: Carry only system properties

UQL
find().edges() as e
return e 
Result
|-------------------- @rate -------------------|
| _uuid | _from | _to  | _from_uuid | _to_uuid |
|-------|-------|------|------------|----------|
|   1   | S001  | M001 | 1          | 4        |
|   2   | S003  | M002 | 3          | 5        |

|------------------ @wishlist -----------------|
| _uuid | _from | _to  | _from_uuid | _to_uuid |
|-------|-------|------|------------|----------|
|   3   | S002  | M001 | 2          | 4        |
|   4   | S003  | M001 | 3          | 4        |

Return PATH

Example: Carry some custom properties

UQL
n({@account}).e({@rate}).n({@movie}) as p
return p{name}{*}
Result
[
  {
    "nodes":[
      {"id":"S001","uuid":"1","schema":"account","values":{"name":"Pepe"}},
      {"id":"M001","uuid":"4","schema":"movie","values":{"name":"Léon"}}
    ],
    "edges":[
      {"uuid":"1","from":"S001","to":"M001","from_uuid":"1","to_uuid":"4","schema":"rate","values":{"score":"9"}}
    ],
    "length":1
  },
  {
    "nodes":[
      {"id":"S003","uuid":"3","schema":"account","values":{"name":"Emma"}},
      {"id":"M002","uuid":"5","schema":"movie","values":{"name":"Avatar"}}
    ],
    "edges":[
      {"uuid":"2","from":"S003","to":"M002","from_uuid":"3","to_uuid":"5","schema":"rate","values":{"score":"8"}}
    ],
    "length":1
  }
]

Example: Carry only system properties

UQL
n({@movie}).e({@rate}).n({@account}).e({@wishlist}).n({@movie}) as p
return p
Result
[
  {
    "nodes":[
      {"id":"M002","uuid":"5","schema":"movie","values":{}},
      {"id":"S003","uuid":"3","schema":"account","values":{}},
      {"id":"M001","uuid":"4","schema":"movie","values":{}}
    ],
    "edges":[
      {"uuid":"2","from":"S003","to":"M002","from_uuid":"3","to_uuid":"5","schema":"rate","values":{}},
      {"uuid":"4","from":"S003","to":"M001","from_uuid":"3","to_uuid":"4","schema":"wishlist","values":{}}
    ],
    "length":2
  }
]

Return TABLE

Example: Find 1-step path @account-@movie, assemble the name of accounts and movies into a table

UQL
n({@account} as a).e({@wishlist}).n({@movie} as b)
return table(a.name, b.name)
Result
| a.name | b.name |
|--------|--------|
| Lina   | Léon   | 
| Emma   | Léon   | 

Return ATTR - Atomic

Example: Return custom properties of nodes independently

UQL
find().nodes() as n
return n.name, n.age, n.year 
Result - n.name
Pepe
Lina
Emma
Léon
Avatar
Result - n.age
24
23
26
null
null
Result - n.year
null
null
null
1994
2009

Analysis: A null will be returned when calling a property that is not existent.

Return ATTR - List

Example: Assemble the name of 1-Hop neighbors of each movie into a list

UQL
khop().n({@movie} as a).e().n() as b
group by a
return a.name, collect(b.name)
Result - a.name
Léon
Avatar
Result - collect(b.name)
["Pepe","Lina","Emma"]
["Emma"]

Valid Return Format

Suppose that nodes, edges, paths, mytable, mylist, mypoint and myitem are aliases of type NODE, EDGE, PATH, TABLE, list, point and others, below return formats are supported:

Return FormatReturn Content
Return Type
nodesNode (carrying schema and system properties)NODE
nodes.<property>Node propertyATTR (return null if property does not exist)
nodes.@Node schemaATTR
nodes{<property>, ...}Node (carrying schema, system properties and listed custom properties)NODE
nodes{*}Node (carrying schema, system properties and all custom properties)NODE
edgesEdge (carrying schema and system properties)EDGE
edges.<property>Edge propertyATTR (return null if property does not exist)
edges.@Edge schemaATTR
edges{<property>, ...}Edge (carrying schema, system properties and listed custom properties)EDGE
edges{*}Edge (carrying schema, system properties and all custom properties)EDGE
pathsPath (carrying schema and system properties of metadata)PATH
paths{<property>, ...}{<property>, ...}Path (carrying schema and system properties of metadata, carrying separately listed custom properties of nodes and edges)PATH
paths{*}{<property>, ...}Path (carrying schema and system properties of metadata, carrying all custom properties of nodes and listed custom properties of edges)PATH
paths{<property>, ...}{*}Path (carrying schema and system properties of metadata, carrying listed custom properties of nodes and all custom properties of edges)PATH
paths{<property>}Path (carrying schema, system properties and listed custom properties of metadata)PATH
paths{*}Path (carrying schema, system properties and all custom properties of metadata)PATH
mytableThe whole tableTABLE
mylistThe whole listATTR
mylist[n]The element with index nATTR
mylist[n1:n2]A sub-list formed by element with index n1~n2ATTR
mylist[:n]A sub-list formed by element with index 0~nATTR
mylist[n:]A sub-list formed by element with index n~<length-1>ATTR
mypointThe whole coordinatesATTR
mypoint.xThe coordinate xATTR
mypoint.yThe coordinate yATTR
myitemThe valueATTR