About Incremental Rebuilds
Incremental rebuilds of aggregate tables append new rows and update existing rows that fall within a period of time that you can specify.
Incremental indicators
To specify that you want aggregate tables for a model to be rebuilt incrementally, you simply specify a column in the fact dataset to use as an incremental indicator. This column must have values that increase monotonically, such as a numeric UNIX timestamp showing seconds since epoch, or a Timestamp/DateTime. The values in this column enable the AtScale engine both to append rows to an aggregate table and update rows during an incremental rebuild.
Incremental aggregates are database views that consolidate one or more incrementally-built tables. Periodically, these tables are consolidated to maintain optimal query performance. You can specify how many tables to allow before consolidation takes place. The distribution of data in the underlying aggregate tables is based on the incremental indicator values. Segmenting of tables is based on ranges of values in the incremental indicator. Incremental indicator values are used as an internal tracking mechanism and are not made for querying in the incrementally-built aggregate.
Supported incremental indicator types
AtScale supports the following incremental indicator types:
- Long
- Integer
- Decimal (38,0)
- Timestamp
- DateTime
Be aware of the following:
- Decimal is only supported for Snowflake data warehouses.
- The fully supported precision for TIMESTAMP is up to TIMESTAMP(9) or nanoseconds. When reading a TIMESTAMP(12) value, the last 3 digits are truncated.
- For Google BigQuery, you can use the Timestamp Incremental Indicator to lower your costs by leveraging Timestamp-based partition pruning.
Appending Rows
During an incremental aggregate build, AtScale retrieves rows from the fact dataset that have an incremental indicator value greater than the last value recorded in the incremental aggregate.
Example
Suppose that the last incremental indicator key value used in the incremental aggregate is 1475191168000 (the UNIX timestamp in seconds since epoch for Thu, 29 Sep 2016 23:19:28 GMT). When an incremental rebuild of the aggregate begins, the engine will look in the fact dataset for rows with an incremental indicator value greater than this value, perform the necessary data aggregation, and append rows to the aggregate.
When the incremental indicator column type is a Timestamp, the grace period is always interpreted as Seconds.
Updating Rows
You also specify a grace period when you select a fact dataset's column to use as an incremental indicator. When the AtScale engine starts an incremental build, the grace period determines how far back in time the engine looks for updates to rows in the fact dataset, based on the units that are in the indicator. The engine then updates rows in the aggregate table where the incremental indicator matches those of rows in the fact dataset.
At the start of an incremental rebuild, the AtScale engine runs a query against an aggregate to find the latest incremental indicator to figure out new data that has been added since the last update. The query uses a WHERE filter to only scan data since the last update, which enables table pruning against partitioned fact datasets.
Moreover, if more than one aggregate configured for incremental rebuilds is based on the same fact datasets, the engine runs the query to see what new data has been added since the last update and uses the result for the remaining aggregates. For example, suppose that six aggregates configured for incremental rebuilds are based on the table factinternetsales. The query is run on the first of these six aggregates and the result is used for all six. This process saves time and resources, versus the alternative of running the query for each aggregate.
Example
As in the previous example, suppose that 1475191168000 is the last incremental indicator key value in an aggregate table. The grace period is 86400 seconds (one 24-hour period). The engine looks back in the fact dataset to the first row where the indicator is 86400 seconds earlier than the moment that the incremental build began. The engine also does this in the aggregate table.
Next, the engine compares the data in the fact set with the aggregated data in the aggregate table, moving forward in time in the data until the engine reaches the point in time when the incremental build began. As it compares data, the engine updates the aggregated data when it finds changes in the fact dataset.
Partition-based incremental aggregate rebuilds
Partition-based incremental aggregates are a Public Preview feature.
Although AtScale's standard, view-based incremental aggregate functionality accelerates aggregate build times, it also adds a significant run-time penalty to report queries that select from incrementally built aggregate tables.
If you have encountered this issue, you may want to enable AtScale's partition-based incremental aggregates. This functionality leverages the data warehouse's native partition (or cluster block) pruning capabilities when building and querying incremental aggregates, thereby reducing the run-time query overhead observed in the view-based implementation.
Partition-based incremental aggregates are only supported for the following data warehouse platforms: Snowflake, Databricks, BigQuery, and Redshift.
The following sections describe how partition-based incremental aggregates work in AtScale.
Incremental indicators and grace periods
Like AtScale's view-based incremental aggregate functionality, partition-based incremental aggregates rely on an incremental indicator to track changes in the data, and a grace period to account for data that may have arrived late. For more information on how these work, refer to Incremental indicators above.
Partition keys
When configuring partition-based incremental aggregate rebuilds, you must define a partition key. This is added to the aggregate definition and used to update it.
You define the partition key by including the following values on the dataset:
- Incremental Indicator Column for Agg Partition: A calculated column on the physical fact table, whose formula defines how the indicator values map to the partition boundaries.
- Partition Dimension: The dimension that contains the level you want to use as the partition key column.
- Partition Hierarchy: The hierarchy that contains the level you want to use as the partition key column.
- Partition Level: The level you want to use as the partition key column. The key of the selected level must not be a string.
If you also define a partition key on the aggregate itself, the system does not build aggregates incrementally. Instead, it builds a non-incremental aggregate with the user-defined partition. (Note that this only applies when AtScale is configured to build partition-based incremental aggregates.)
Incremental rebuilds of aggregates that use joins
You can create aggregate tables that use joins to one or more dimensional datasets, and such aggregate tables can be rebuilt incrementally. When configuring this, be sure that the joined dimensions rarely (if ever) change outside of the grace period. Additionally, the datasets these dimensions are based on should have the Immutable option enabled in the Dataset properties panel.
For more information, see Aggregates for Fact Datasets that Use Joins and Configuring Incremental Aggregate Rebuilds.