Skip to main content

Tables and rows

AQL is a data query language. Like SQL or Excel, it operates on tables: collections of rows, where each row has columns. Before we touch any function, it helps to get precise about what AQL actually does as it reads your data.

Try it interactively

Practice in the AQL Playground: Metric Expressions.

A tiny example

Imagine an order_items table:

idorder_idproductquantityprice
11001Mug210
21001Pen52
31002Book125

Three rows, five columns. AQL operates on tables like this one.

The current row

Unlike Excel, you can't point at a single cell. The smallest thing AQL works on is a row. When AQL processes a table, it walks through the rows one at a time. The row it's currently looking at is called the current row.

Inside the current row, you refer to columns by name. So order_items.quantity means "the quantity column of whatever row I'm on right now". As AQL walks the table above, that expression evaluates to 2, then 5, then 1.

You can combine columns too. order_items.quantity * order_items.price is a row-level expression: it runs once per row, giving 20, then 10, then 25.

Iteration

That walk-through-the-rows process is called iteration. Most AQL functions iterate. A few you'll meet next:

  • select: walks rows, produces a new table with just the columns you ask for.
  • filter: walks rows, keeps only the ones matching a condition.
  • sum: walks rows, adds up a column into one number.

For example, the total revenue across the table:

order_items | sum(order_items.quantity * order_items.price)
// walks all 3 rows, computes 20 + 10 + 25 = 55

Don't worry about the | yet (that's the next page). The point for now: any expression you hand to one of these functions is evaluated once per row.

Next

The pipe operator: how AQL chains operations together.


Open Markdown
Let us know what you think about this document :)