Skip to main content

Use case

A common modeling problem is computing a metric that depends on two inputs which change at very different rates:
  • A large fact table that is expensive to aggregate and only needs to be refreshed on a slow cadence (for example, daily or hourly).
  • A small lookup table whose values are applied to each fact row and that needs to be refreshed much more frequently than the fact aggregation.
Some examples of this pattern:
  • Converting an amount column to a target currency using the latest foreign exchange (FX) rates — either a single-currency column multiplied by a rate, or an amount and currency column resolved with a CASE statement.
  • Re-pricing inventory or order lines with a frequently-updated price list.
  • Applying a frequently-tuned scoring weight, tax rate, or commission rate to historical events.
Combining both inputs into a single rollup forces the entire pre-aggregation to refresh whenever the lookup values change, which is wasteful. In the recipe below, we’ll learn how to use a rollup join to keep each pre-aggregation on its own refresh schedule while still serving the combined, derived query from pre-aggregations. We’ll walk through the FX conversion variant as a concrete example, but the same pattern applies to any of the use cases above.
rollup_join has several constraints documented on the pre-aggregations reference page. In particular: it is currently in Preview, it is designed for joining data across data sources, it can only join two rollups, and it is ephemeral — set freshness controls on the referenced rollups rather than on the rollup_join itself.The rollup on the right side of the join is also bounded by the number of physical Cube Store partitions it can have, which depends on your Cube Store compute tier. Note that these are Cube Store physical partitions — not Cube logical partitions.

Data modeling

We have two cubes: orders, which stores per-order amounts in the original transaction currency, and fx_rates, which stores the latest exchange rate from each currency to USD. The orders table looks like this: The fx_rates table looks like this: First, define a rollup pre-aggregation on orders that aggregates the amount by currency and day. This is the heavy pre-aggregation, so we set a slow refresh_key — for example, every day:
Next, define a rollup pre-aggregation on fx_rates. This pre-aggregation is small (one row per currency) and cheap to rebuild, so we give it a much faster refresh_key than the orders rollup — for example, every hour:
Both pre-aggregations must include an index on the join key (currency in this example) for the rollup_join to match. The fx_rates_rollup also needs rate_to_usd as a dimension so it’s available downstream.
Finally, define a rollup_join pre-aggregation on orders that references both rollups. This is an ephemeral pre-aggregation — it doesn’t materialize its own data, so it doesn’t need a refresh_key. Cube serves queries from it by joining the two underlying rollups on the fly:
To expose the USD-converted amount, add a derived measure on orders that multiplies the order amount by the FX rate from the joined cube:

Query

Let’s query daily sales in USD by currency:

Result

Cube serves the query from orders_with_fx_rollup, joining the cached orders_rollup (refreshed daily) with the cached fx_rates_rollup (refreshed hourly). The heavy aggregation never rebuilds when FX rates change, but the converted totals always reflect the latest rates.