Structure Type of Alias
Alias is to name the data columns generated during the execution of UQL, so that the data columns can be called in the subsequent UQL statment.
There are 6 structure types a alias can represent:
Structure Type |
Definition Example | Alias Example |
Data Structure Example |
---|---|---|---|
NODE | n(as nodes).e().n() | nodes | {id: , uuid: , schema: , values: {...}} |
EDGE | n().e({time > prev_e.time})[3].n() | prev_e | {uuid: , schema: , from: , from_uuid: , to: , to_uuid: , values: {...}} |
PATH | n().e().n() as paths | paths | {nodes: [<NODE> , <NODE> , ...], edges: [<EDGE> , <EDGE> , ...]} |
ATTR | uncollect ["Alice","Paal"] as name uncollect ["1993-06-12","1989-03-26"] as birthday |
name birthday |
Atomic data without internal structure, such as string, number and so on |
ARRAY | n().e()[3].n() as paths with pedges(paths) as edgeUUIDs |
edgeUUIDs |
[<ATTR> , <ATTR> , ...] |
TABLE | uncollect ["Alice","Paal"] as name uncollect ["1993-06-12","1989-03-26"] as birthday with table(name, birthday) as record |
record |
{headers: [], table_rows: [<ARRAY> , <ARRAY> , ...]} |
Not defining alais for data stream generatd during the execution of UQL, or not calling an alias defined could have negative effect on the legality of UQL. Please avoid missing defining alias or defining alias that is not called later on.
Custom Alias
A custom alias is defined by the user. The nodes
, paths
, name
, birthday
, edgeUUIDs
and record
in the previous table are all custom aliases.
Rules of defining a custom alias:
- Use alias keyword
as
; - Please refer to chapter Basic Concepts for the naming conventions of alias
- Note that custom alias also accepts only 1 character.
- Cannot have the same name with existing custom alias, nor can system reserved words be used (see chapter Basic Concepts for details).
- Try to avoid duplicate names with the property names of the nodes or edges to be used in the same statement; if this is not possible, system alias
this
may be used to disambiguate if necessary.
Structure types a custom alias may represent: NODE, EDGE, PATH, ATTR, ARRAY, TABLE
Life cycle of a customer alias: anywhere after the alias is defined.
In case an alias cannot be called by a statment far from where this alias is defined, re-defining alias for that data column in a WITH clause my solve the problem.
System Alias
A system alias is defined by the system. There are 3 system aliases, prev_n
, prev_e
and this
. They can be used directly without definition:
System Alias | Meaning | Structure Type | Life Cycle |
---|---|---|---|
this |
Current node or edge | NODE or EDGE | In any filter |
prev_n |
The previous node of the current node or edge | NODE | In the filter of any baisc template |
this |
The previous edge of the current node or edge | EDGE | In the filter of any baisc template |
Please read chapter Template for details on prev_n
and prev_e
.
In practical applications, this
is rarely used unless to eliminate any ambiguity; ambiguity occurs when the names of the node/edge's property and the custom alias are repeated, this
has to be used in this case if there is a need to refer to the property of node/edge.
... as balance
find().nodes({this.balance > 5000})
Note: In this example, this.balance
in nodes()
represents the balance property of the current node; since the custom alias defined in the previous statement is still valid in the current statement, using balance
in nodes()
directly conflicts with the name of node's property balance, so that this
is used.
Call an Alias
When calling the alias of ATTR, ARRAY or TABLE, the complete data structure will be called.
When calling the alias of NODE, EDGE or PATH, use different call format to either call the JSON structure with complete KVs, or the JSON with partial KVs, or just one KV from the JSON.
Suppose that nodes
, edges
and paths
are aliases of NODE, EDGE or PATH, below call formats are supported:
The alias of NODE, EDGE and PATH in the RETURN clause carries schema and system properties (
_uuid
,_id
,_from
,_to
,_from_uuid
,_to_uuid
) of nodes and/or edges by default, this information covers the table below.
Call Format | Call Type |
Specification | Meaning |
---|---|---|---|
nodes |
NODE | Call in any statement | Nodes that do not carry any custom properties |
nodes.<property> |
ATTR | Call in any statement | A property of the nodes (or empty if the property does not exist; the same below) |
nodes.@ |
ATTR | Call in any statement | Schemas of the nodes |
nodes{<property>, ...} |
NODE | Call in RETURN clause | Nodes that carry several custom properties |
nodes{*} |
NODE | Call in RETURN clause | Nodes that carry all custom properties |
edges |
EDGE | Call in any statement | Edges that do not carry any custom properties |
edges.<property> |
ATTR | Call in any statement | A property of the edges |
edges.@ |
ATTR | Call in any statement | Schemas of the edges |
edges{<property>, ...} |
EDGE | Call in RETURN clause | Edges that carry several custom properties |
edges{*} |
EDGE | Call in RETURN clause | Edges that carry all custom properties |
paths |
PATH | Call in any statement | Paths that do not carry any custom properties of its nodes and edges |
paths{<property>, ...}{<property>, ...} |
PATH | Call in RETURN clause | Paths that carry several custom properties of its nodes and edges |
paths{*}{<property>, ...} |
PATH | Call in RETURN clause | Paths that carry all custom properties of its nodes and several custom properties of its edges |
paths{<property>, ...}{*} |
PATH | Call in RETURN clause | Paths that carry several custom properties of its nodes and all custom properties of its edges |
paths{*} |
PATH | Call in RETURN clause | Paths that carry all custom properties of its nodes and edges |
User may gradually comprehend the concepts above as continue reading.
Read chapter Data Stream, Clause for the detailed description of RETURN.