Cube provides a solution to this problem: pre-aggregations. In layman’s terms, a
pre-aggregation is a condensed version of the source data. It specifies
attributes from the source, which Cube uses to condense (or crunch) the data.
This simple yet powerful optimization can reduce the size of the dataset by
several orders of magnitude, and ensures subsequent queries can be served by the
same condensed dataset if any matching attributes are found.
Pre-aggregations are defined within each cube’s data
model, and cubes can have as many pre-aggregations as they
require. The pre-aggregated data is stored in Cube Store, a dedicated pre-aggregation storage
layer.
Pre-Aggregations without Time Dimension
To illustrate pre-aggregations with an example, let’s use a sample e-commerce database. We have a data model representing all ourorders:
Our first requirement is to populate a dropdown in our front-end application
which shows all possible statuses. The Cube query to retrieve this information
might look something like:
orders cube:
Pre-Aggregations with Time Dimension
Using the same data model as before, we are now finding that users frequently query for the number of orders completed per day, and that this query is performing poorly. This query might look something like:orders cube:
granularity property with a value of month to this
definition. This allows Cube to aggregate the dataset to a single entry for each
month.
The next time the API receives the same JSON query, Cube will build (if it
doesn’t already exist) the pre-aggregated dataset, store it in the source
database server and use that dataset for any subsequent queries. A sample of the
data in this pre-aggregated dataset might look like: