AQL ReferenceFunctionsTable functions
filter
AQL Syntax: Extract the records that match the conditions
Definition
Get a subset of rows from table that match one or more condition.
Syntax
filter(table, condition, condition, ...)filter(orders, orders.status == 'refunded') //-> Table(orders.id, orders.status, ...)
filter(orders, orders.is_cancelled) // -> Table(orders.id, orders.status, ...)
// with pipe
orders | filter(orders.status == 'refunded') //-> Table(orders.id, orders.status, ...)
orders
| select(orders.id, orders.status)
| filter(orders.status == 'refunded') //-> Table(orders.id, orders.status)
// multiple conditions
orders
| filter(orders.status == 'refunded', orders.is_cancelled)
| select(orders.id) //-> Table(orders.id)Input
-
table: A model reference or the returned table from a previous expression. -
condition(repeatable): A formula returning a truefalse value. Eachconditionis evaluated over each row oftable:- If the
conditionevaluates to true, the row is included in the output table. - If the
conditionevaluates to false, the row is excluded from the output table.
Note: If multiple
conditionare provided, they are evaluated as a logical AND. For example,filter(orders, orders.status == refunded', orders.is_cancelled)is equivalent tofilter(orders, and(orders.status == refunded', orders.is_cancelled)). - If the
Output
A new table that contains all rows in table that match the condition.
Sample Usages
orders
| filter(countries.name == "Vietnam", orders.created_at matches @2022-08)
| select(orders.id, orders.user_id)| orders->id | orders->user_id |
|---|---|
| 30501 | 2316 |
| 30521 | 3793 |
| 30824 | 3352 |
| 31369 | 381 |
| 31545 | 2607 |
Any expression that can be used in select column, can be used in filter condition.
orders | group(orders.status) | filter(count(orders.id) > 1000)
// is equivalent to
// orders
// | group(orders.status)
// | select(orders.status, condition: count(orders.id) > 1000)
// | filter(condition)| orders->status |
|---|
| delivered |
See also
where(): applies on metrics, not tablesselect()group()- where vs filter
- Pipe operator