Use cases
Below we are looking at the most common examples of using lambda pre-aggregations.Batch and source data
Batch data is coming from pre-aggregation and real-time data is coming from the data source.batch. Please note, it must have a
time_dimension and partition_granularity specified. Cube will use these
properties to union batch data with freshly-retrieved source data.
You may also control the batch part of your data with the build_range_start
and build_range_end properties of a pre-aggregation to determine a specific
window for your batched data.
Next, you need to create a lambda pre-aggregation. To do that, create
pre-aggregation with type rollup_lambda, specify rollups you would like to use
with rollups property, and finally set union_with_source_data: true to use
source data as a real-time layer.
Please make sure that the lambda pre-aggregation definition comes first when
defining your pre-aggregations.
The source data part is read with a row limit, set by
CUBEJS_MAX_SOURCE_ROW_LIMIT (200000 by default).
If the source query reaches it, the query fails with an error instead of
returning truncated data. Raise the limit or narrow the window not covered by
the batch rollup.Batch and streaming data
In this scenario, batch data is comes from one pre-aggregation and real-time data comes from a streaming pre-aggregation.Overlapping build ranges
A partition that isn’t fully built is skipped for every rollup except the last one. When the build range of a rollup starts exactly where the previous one ends, the partition that has just become complete, for example the previous day right after midnight, is served by no rollup until it’s rebuilt. Such days are missing from query results without an error. To avoid that, start the build range of each rollup earlier than the build range of the previous one ends, with a margin longer than the previous rollup’srefresh_key interval plus its build time. Rows are not counted twice: a rollup
skips partitions that the previous one already serves.
partition_granularity than the next one, the next
rollup has to start before the beginning of the previous rollup’s last partition,
because that whole partition is skipped until it’s complete. For example, with
month partitions on batch and day partitions on hot, start hot at
date_trunc('month', CURRENT_DATE - INTERVAL '16 days').