Hello everyone,
I need to recursively/cyclically calculate data by months with intermediate saves to the database, as the next period will be calculated/saved based on these data.
Details:
- We have data based on which a month’s calculations are made.
- The next month is calculated based on these results, and so on until all missing months are calculated and saved.
- Each monthly calculation involves 4-5 complex views.
In another stack (not dbt + airflow), this is solved as follows:
- Calculate the month based on initial data.
- Save the results to a technical table.
- Calculate the next month based on the technical table.
- Repeat until completion.
In dbt, this can theoretically be implemented in several ways:
- Write a custom materialization scheme.
- Adapt the experimental insert-by-period.
- Use templates to generate the entire calculation through Jinja in one pass (though this could be cumbersome and resource-intensive).
Another considered option is to create simple models for the initial and n-th monthly calculations and organize multiple runs via airflow:
However, the customer has limited access to airflow, making DAG debugging inconvenient.
When attempting to use insert-by-period, the following error occurred:
column "__period_filter__" does not exist
LINE 15: where __PERIOD_FILTER__
Does anyone have any ideas on how this can be correctly implemented in dbt? Is there a proper way to use insert-by-period or another approach?
Thank you in advance!