Overview
A filter sets conditions for retrieving nodes and edges based on schemas and properties and is used within certain clause methods.
In UQL, filters are enclosed in {}
. Filter expressions typically contain comparison operators like =
, >
and <
and logical operators like AND
and OR
. Each filter expression evaluates to a boolean or null
, validating nodes or edges when the expression returns TRUE.
General Filter
In this example, the filter {@user || @movie.rating > 3}
specifies that the clause retrieves @user
nodes or @movie
nodes with a rating
greater than 3:
find().nodes({@user || @movie.rating > 3}) as n
return n{*}
Simplified Filter
In this example, the filter {age}
specifies that the clause retrieves nodes with an age
property whose value, when subtracted by 30, is non-zero:
find().nodes({age - 30}) as n
return n{*}
The table below demonstrates how different data types are evaluated as TRUE or FALSE:
Type |
TRUE | FALSE |
---|---|---|
int32 ,uint32 ,int64 ,uint64 ,float ,double |
Non-Zero | 0 |
string ,text |
Does not start with the character "0" | Starts with the character "0" |
datetime |
Any date except 0000-00-00 00:00:00 |
0000-00-00 00:00:00 |
timestamp |
Any date except 1970-01-01 08:00:00 +08:00 or equivalent |
1970-01-01 08:00:00 +08:00 or equivalent |
point |
Never | Any value |
list |
Never | Any value |
Inter-Step Filter
In a path template clause, you can employ the system alias prev_n
or prev_e
to facilitate inter-step filtering.
This example searches for 4-step outgoing transaction paths between @card
nodes, ensuring ascending transaction times:
n({@card}).re({@transfers}).n({@card})
.re({@transfers.time > prev_e.time})[3]
.n({@card}) as p
return p{*}
Any property called by prev_n
or prev_e
, such as the time
property in the example, must be LTE-ed for acceleration.