Skip to main content

AQL Pipe

Knowledge Checkpoint

This documentation assumes you are familiar with the following concepts:

Definition

Syntax
expression | function_call()

Pipe works like this: users | avg(users.age) is equivalent to avg(users, users.age). In general, this means the part before the pipe is fed into the function behind the pipe as the first argument.

Unlike SQL, where the whole query requires to be a fixed pattern (select...from...where...group by...), AQL allows a query to be broken down into smaller components joined by the "pipe operator". We believe this syntax allows for a more natural way to map user's mental model to the resulting query.


Example

Suppose we have a dataset with the following model:

Dataset ecommerce {
models: [orders]
}

Model orders {
dimension country {}
dimension total_value {}
}

And we want to calculate the total sales of Singapore. We will use the two functions, filter() and sum()

filter(table_expr, filter condition) // -> Table
sum(table_expr, field_ref) // -> Number

These two functions accept a Table as their first argument.

and write a pipeline to calculate the number above:

orders | filter(orders.country = 'Singapore') | sum(orders.total_value)

What happened in this example:

  • Model orders is passed into filter()’s first argument. filter() apply the condition on it, and produce a new Table (let’s call it filtered_orders)
  • Table filtered_orders is then piped into sum()'s first argument, and the function produces the final result.

Let us know what you think about this document :)