Skip to content

Commit d2d4977

Browse files
authored
docs: add materialization_role configuration for pre-aggregates (#530)
This pull request adds support for the `materialization_role` parameter in pre-aggregates configuration. This new parameter allows users to define fixed user attributes that will be used when materializing pre-aggregates, ensuring consistent materialization results regardless of which admin triggers the process. The change addresses scenarios where models use user attributes in SQL filters (like `${ld.attr.allowed_regions}`). Without this feature, the materialized pre-aggregate would only contain data accessible to the specific admin who triggered materialization. With `materialization_role`, users can specify a fixed set of attributes (such as all allowed regions: EMEA, APAC, NA) to ensure complete data materialization while still applying proper user-specific filtering at query time. The documentation includes configuration examples for both dbt v1.9/earlier and dbt v1.10+/Fusion, showing how to set the email and attributes for the materialization role.
1 parent 18ea1fd commit d2d4977

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

references/pre-aggregates/getting-started.mdx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Pre-aggregates are defined under the `pre_aggregates` key in your model configur
7171
| `granularity` | No | Time granularity for the `time_dimension`. Valid values: `hour`, `day`, `week`, `month`, `quarter`, `year`. Must be paired with `time_dimension`. |
7272
| `max_rows` | No | Maximum number of rows to store in the materialization. If the aggregation exceeds this limit, the result is truncated. Must be a positive integer. |
7373
| `refresh` | No | Schedule configuration for automatic re-materialization. See [Scheduling refreshes](#scheduling-refreshes). |
74+
| `materialization_role` | No | Fixed user attributes to use when materializing the pre-aggregate. See [Materialization role](#materialization-role). |
7475

7576
<Note>
7677
If you specify `time_dimension`, you **must** also specify `granularity`, and vice versa.
@@ -143,6 +144,71 @@ You can set `max_rows` to cap the size of a materialization. If the aggregation
143144
When `max_rows` is applied, some data is excluded from the materialization. Queries that match the pre-aggregate may return incomplete results. Use this setting carefully and monitor for the "max rows applied" warning in the [monitoring UI](/references/pre-aggregates/monitoring).
144145
</Warning>
145146

147+
## Materialization role
148+
149+
If your model uses user attributes in SQL, the user who triggers the materialization can affect what gets stored in the pre-aggregate.
150+
151+
For example, if the model has `sql_filter: "customers.region IN (${ld.attr.allowed_regions})"`, the materialized table will only contain the regions that the admin who triggered the materialization happens to have access to. If that admin has `allowed_regions: ["EMEA"]`, the pre-aggregate will only contain EMEA rows.
152+
153+
Use `materialization_role` to define a fixed set of user attributes for materializing the pre-aggregate. At query time, Lightdash ignores `materialization_role` and uses the real viewer user's attributes instead, so a user with `allowed_regions: ["EMEA"]` still only sees EMEA rows.
154+
155+
<Tabs>
156+
<Tab title="dbt v1.9 and earlier">
157+
```yaml
158+
models:
159+
- name: orders
160+
meta:
161+
joins:
162+
- join: customers
163+
sql_on: ${customers.customer_id} = ${orders.customer_id}
164+
sql_filter: "customers.region IN (${ld.attr.allowed_regions})"
165+
pre_aggregates:
166+
- name: orders_daily_by_region
167+
dimensions:
168+
- customers.region
169+
metrics:
170+
- total_order_amount
171+
time_dimension: order_date
172+
granularity: day
173+
materialization_role:
174+
email: materialize@acme.com
175+
attributes:
176+
allowed_regions:
177+
- EMEA
178+
- APAC
179+
- NA
180+
```
181+
</Tab>
182+
<Tab title="dbt v1.10+ and Fusion">
183+
```yaml
184+
models:
185+
- name: orders
186+
config:
187+
meta:
188+
joins:
189+
- join: customers
190+
sql_on: ${customers.customer_id} = ${orders.customer_id}
191+
sql_filter: "customers.region IN (${ld.attr.allowed_regions})"
192+
pre_aggregates:
193+
- name: orders_daily_by_region
194+
dimensions:
195+
- customers.region
196+
metrics:
197+
- total_order_amount
198+
time_dimension: order_date
199+
granularity: day
200+
materialization_role:
201+
email: materialize@acme.com
202+
attributes:
203+
allowed_regions:
204+
- EMEA
205+
- APAC
206+
- NA
207+
```
208+
</Tab>
209+
</Tabs>
210+
211+
With this setup, the materialized table always contains EMEA, APAC, and NA rows regardless of who triggered the materialization. When a viewer queries the pre-aggregate, Lightdash applies their own user attributes to the query, not the `materialization_role`.
146212

147213
## Complete example
148214

0 commit comments

Comments
 (0)