Format, Parameters
RETURN can perform functional operations on the data stream, and combine multiple values (columns) before sending back to client end. Input columns that are non-homogeneous will be trimmed to the shortest length of homogeneous group (or without trimming V4.1 )).
Syntax:
- Format: return
<column1>
as<alias1>
,<column2>
as<alias2>
, ... - Parameters: see table below
- Affected columns:
<column>
and all its homologous columns
Name | Category | Specification | Description |
---|---|---|---|
<column> |
NODE,EDGE,PATH,ATTR,ARRAY,TABLE | / | Returned value, multiple returned values can be homologous columns or non-homologous columns |
<alias> |
string | With the same naming convention as custom alias | Alias of returned values, omittable |
Analysis
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 statement above, RETURN returns 3 values, their types are NODE,ARRAY,ATTR respectively; because the first column are not homologous with the latter two columns, Ultipa Engine V4.0 will not return data under the red line as shown in the image below
Deduplication operation on certain column in RETUEN does not affect the lengths of homologous columns. RETURN often appears in the end of an UQL statement, it can also be followed by ORDER BY, LIMIT, or SKIP in some cases.
For information on how to designate properties of NODE, EDGE, or PATH in RETURN clause, please refer to Chapter Query - Returned Value .
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 proproties, 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 sechma 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 inntial 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)