Skip to main content

Use case

We want to disable pre-aggregations unless some condition is fulfilled, e.g., unless the deployment is running in a production environment.

Data modeling

You can add an environment variable and use it in data model files to enable or disable pre-aggregations.

YAML files

In YAML data model files, you can use Jinja with the built-in env_var function:
env_var always returns a string, and any non-empty string is truthy in Jinja. A bare {% if env_var('PRE_AGGREGATIONS_ENABLED') %} keeps pre-aggregations enabled even when the variable is set to false, so compare the value explicitly, as above. Pre-aggregations stay enabled unless the variable is set to false. Jinja also processes YAML comments. Do not put {%, {{, %}, or }} inside a # comment in a file that uses Jinja.

JavaScript files

In JavaScript data model files, you can use JavaScript with an auxiliary file that exports your environment variable. Consider the following file structure:
Note that you will have to adjust the pre-aggregation definition to account for the context symbol transpilation. This is the reason why measures are defined as such above.