AMQL Docs
AQL ReferenceGrammar

Explore Expressions

Explore expressions act as an intermediate AQL layer that auto-selects tables from your dimensions and measures, so you never write Table expressions by hand.

An explore expression is the top-level query form of AQL: a declarative block that names the dimensions, measures, filters and relationship overrides you want, and leaves the choice of tables and joins to the compiler.

It is the intermediate representation between a question and SQL. A person can write one by hand, as every example in these docs does, and a tool built on AMQL generates one from a user's selections. Either way the compiler turns it into the final SQL query.

Structure

explore {
  dimensions {
    dimension1,
    dimension2
    ...
  }
  measures {
    measure1,
    measure_name2: measure2 // you can also specify a custom name for the measure
    ...
  }
  filters { //optional
    logical_expression1,
    logical_expression2
    ...
  }
  relationships { // optional
    relationship1,
    relationship2
    ...
  }
}

Explore vs Table Expressions

You can think of an Explore expression as a semi-automated version of a Table expression. The key difference is the fact that the Explore expression will automatically choose the right tables to query from based on the dimensions and measures you have defined.

For example, given the following Explore expression:

explore {
  dimensions {
    users.name
  }
  measures {
    count_orders: count(orders.id)
  }
}

It is equivalent to the following Table expression:

orders
| group(users.name)
| select(users.name, count_orders: count(orders.id))

Notice that in the Table expression, we have to manually specify the orders table to query from. In the Explore expression, you don't have to do that: the compiler chooses the right tables to query from based on the dimensions and measures you have chosen.

Examples

explore {
  dimensions {
    merchants.name
  }

  measures {
    count_merchants_products: count(products.id)
      | with_relationships(products.merchant_id > merchants.id),
    count_products_bought: count(products.id)
  }

  filters {
    merchants.name == "John"
  }
}

On this page