Skip to main content

Metric

A metric is an aggregated outcome derived from a particular model. It consists of the following parts:

  1. measure

    A measure is a quantifiable value or a calculated statistic that provides information about a specific aspect of the data. Measures are typically numerical and represent the outcomes or results of interest in a dataset.

  2. dimension

    A dimension refers to a distinct attribute or characteristic that provides context to the data being analyzed. It represents a category or a variable that helps to categorize or segment the data.

  3. time grain

    Time grain refers to the level of granularity or detail at which data is captured and analyzed over time. It determines the time interval or period over which measurements or observations are made.

An example to show how to define a metric

Metric Revenue @model(Orders) {
total_revenue: INTEGER @measure(sum(totalprice))
orderstatus: OrderStatus @dim
custkey: INTEGER @dim
orderdate_grain: date @time_grain(orderdate, [DAY, MONTH])
}

Now, we can query Revenue like

SELECT orderstatus, total_revenue FROM Revenue
SELECT orderstatus, total_revenue FROM roll_up(Revenue, orderdate_grain, DAY) -- time grain

More way to query a metric, see How to query metrics ?

Pre-Aggregation for a Metric

An Metric can be marked as a pre-aggregated metric like

Metric Revenue @model(Orders) @preAgg {
total_revenue: INTEGER @measure(sum(totalprice))
orderstatus: OrderStatus @dim
custkey: INTEGER @dim
orderdate_grain: date @time_grain(orderdate, [DAY, MONTH])
}

A pre-aggregated metric will be generated when the Accio server is started. The result of a metric will be cached in DuckDB . All query invoking the specific metric will be executed in DuckDB. More detail about pre-aggregation, see How to do Pre-Aggregation for a Metric