RETURN can perform functional operations on the data stream and assemble 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
For information on how to designate properties of NODE, EDGE, or PATH in RETURN clause, please refer to Chapter Query - Alias System .
find().nodes() as n1 limit 5
n(3).e()[2].n(as n2) as path
return n1, pnodes(path), distinct(n2.color)
In the UQL above, RETURN assembles 3 values whose structures are NODE, ARRAY and ATTR; the first value are heterologous with the latter two values; the deduplication against the 3rd value does NOT affect the 2nd value, which is homologous with the 3rd value, as the deduplication is operated in RETRUN:
NODE
Example: return 10 nodes with all their properties
find().nodes() as n
limit 10
return n{*}
Example: find 50 nodes that are @card or @customer, return properties balance or level
find().nodes({@card || @customer}) as n
limit 50
return n{balance, level}
Analysis: @card nodes have both balance and level as properties, while @customer nodes only have level. Returned results only contain properties the nodes have.
EDGE
Example: return 50 edges without customized properties
find().edges() as e
limit 50
return e
PATH
Example: return 10 three-step paths without any customized node or edge properties
n().e()[3].n() as p
limit 10
return p
Example: return 10 one-step transfer paths between customers' cards, return them with balance and time
n({@customer}).e().n({@card})
.e().n({@card})
.e().n({@customer}) as p
limit 10
return p{balance}{time}
Analysis: returned values only contains properties the schema has. In this example, @card has balance
, @transfer has time
, and all nodes and edges have system properties and schema.
Example: return 10 one-step transfer paths among customers' cards, with all nodes carrying all their properties and edges carrying no custom properties.
n({@customer}).e().n({@card})
.e().n({@card})
.e().n({@customer}) as p
limit 10
return p{*}{}
Example: return 10 one-step transfer paths among customers' cards, with all nodes and edges carrying all their properties.
n({@customer}).e().n({@card})
.e().n({@card})
.e().n({@customer}) as p
limit 10
return p{*}
ATTR
Example:find 100 edges, return their schema name and amount (if applicable)
find().edges() as e
limit 100
return e.@, e.amount
Analysis: egdes without amount
will return null in e.amount
Example: find the highest balance among all cards
find().nodes({@card}) as n
return max(n.balance)
ARRAY
Example: find 10 cards, aggregate Card IDs in arrays and return
find().nodes({@card}) as n
limit 10
return collect(n._id)
Table
Example: find 10 transfer edges, aggregate intial cards' IDs, terminal cards' IDs, transfer amounts in tables and return
n(as n1).e({@transfer} as e).n(as n2)
limit 10
return table(n1._id, n2._id, e.amount)