Expression
Expression is a syntactical arithmetic combination of Operator and Operand. In UQL, expression appears in both filters and clauses, and each expression has a value.
-
Operator: conditional operators, logical operators, numeric operators (see the next article for operators and their precedence)
-
Operand: constant, alias, function, current schema, current property
Operand | Examples | Expression Examples (in filters) |
---|---|---|
Constant | 1,"abc", "2020-01-01 0:0:0" | {1+3*2} |
Alias | nodes,edges,paths | {nodes.level},{edges.amount < 2000} |
Function | now(),count(nodes),year("2022-04-12") | {year(edges.time) > 2020} |
Current schema | this.@ | {@ == "card"},{@product} |
Current property | this._id,this.name | {level != 2} |
(The nodes, edges and paths appeared above are the aliases in structure NODE, EDGE and PATH; system alias this that represent the current node or edge is usually omitted, see document Query - Alias System for detail.)
Filter
As shown in the above table, Ultipa filter has below features:
- It is an expression encapsulated in curly bracket
{ }
- It usually (but not necessarily) calls the schema and/or property of current metadata as operands
- Its last operator to run is usually (but not necessarily) conditional operator or logical operator
The expression in the Ultipa filter judges whether the current node/edge meets the filtering condition by producing a boolean value (TRUE or FALSE). Sometimes conversion is needed from non-boolean value to boolean value:
Non Boolean Type | To TRUE | To FALSE |
---|---|---|
Number | When it is NOT 0 | When it is 0 |
string, text, datetime | When the first character is NOT '0' | When the first character is '0' |
timestamp | When it is NOT '1970-01-01 08:00:00 +08:00' or equivalent | When it is '1970-01-01 08:00:00 +08:00' or equivalent |
Example: find 10 cards whose balances are NOT 0
find().nodes({@card.balance}) as n
limit 10
return n{*}
All Ultipa queries employ filtering mechanism when filter for metadata. There are 3 implementation scenarios of Ultipa filter:
Implementation |
Specification |
Example |
---|---|---|
Common filtering | In any query command, to filter current node or edge using constant and alias defined before the query command | {time > "2022-02-24 07:00:00"} |
Inter-step filtering | In template query, to filter current node or edge using precedent nodes or edges in the same path (see document Query - Path|Subgraph|Template for detail) | {time > prev_e.time}, {_uuid == a._uuid} |
Full-text filtering | In any query command, to filter current node or edge against the word segmentation result of any of their properties ( refer to Conditional Operator - Contains and Index | Full-text | LTE - Full-text Filter) | {~content contains "graph ultra* database"} |
(In the above table the time is a property name, a is an alias defined earlier in the same path template, and content is the full-text index for a property)