Datasets
Combine data models into a single, queryable view
A dataset is a container that holds several data models together, along with the join paths between them. It's what agents and dashboards actually query.
Defining a dataset
Put each dataset in its own .aml file under datasets/:
Dataset sales {
label: 'Sales'
data_source_name: 'warehouse'
models: [orders, order_items, products]
relationships: [
relationship(order_items.order_id > orders.id, true),
relationship(order_items.product_id > products.id, true)
]
metric revenue {
label: 'Revenue'
type: 'number'
definition: @aql sum(order_items.quantity * products.price);;
}
}Apps and agents query a dataset by its name, here sales.
Relationships
relationship(a > b, true) joins two models on a key. a is the many side
and b the one side: many order items belong to one order. true makes the
relationship active.
anfra uses the relationships to resolve joins automatically — queries never have to restate them. It also uses their direction to compute each metric at the right level, so a count of orders is not multiplied by the number of items in each order. Getting the direction wrong silently inflates numbers.
What a dataset contains
- Included models — the tables/entities being combined.
- Relationships — the join paths between those models.
- Metrics — named aggregations, which can span multiple included models.
- Dimensions — every dimension of every included model, plus any the dataset adds.
Data models vs. datasets
| Data model | Dataset | |
|---|---|---|
| Represents | One table or query | One or more joined models |
| Aggregations | Measures (single-model) | Metrics (can span models) |
| Changes when | The underlying schema changes | Reporting needs change |
Think of data models as mirroring your database, and datasets as mirroring the questions the business actually asks.