As of Date Tables
An As of Date table contains a single column of dates used to construct the history in tables like PITs and Bridges.
The date range and the date interval size is often informed by the current reporting period and can be changed on the fly. An example of a usual date range could be all dates from the last 3 months.
Periodically, the As of Date table would be refreshed, to accommodate for the new reporting period.
As of Date tables will soon be
The As of Date table consists of a single date/datetime column, and is currently generated using the dbt_utils.date_spine macro.
dbt_utils is another package for dbt, provided by dbt Labs. The date_spine macro above is provided by this package. For more information, go read the date_spine docs here. dbtvault includes dbt_utils as a dependency, and is installed alongside the dbtvault package.
It will require the following input:
Date interval (datepart)¶
This is the parameter that defines the granularity of the date intervals. It needs to be a unit of time (e.g. "hour", "day", "week").
Start Date (start_date)¶
This parameter defines the earliest possible date for the date range. The value for
start_date will be included in the
list of values for
AS_OF_DATE, if it is aligned (i.e. of the same - or lower - granularity) with
End Date (end_date)¶
end_date parameter defines the latest possible date for the date range. The value for
end_date will not be
included in the list of values for
Setting up an As of Date model¶
Create a new dbt model. We'll call this one
1 2 3 4 5
To create an As of Date model, simply copy and paste the above template into a model named
as_of_date (or similar).
With the help of dbt_utils
date_spine function, the template will generate an As of Date table using the parameters
provided in the next steps.
The recommended materialisation for an As of Date table is
To refresh the As of Dates to reflect the new reporting period, you need to change the values in the parameters and run the dbt model again.
Adding the metadata¶
Let's look at the metadata we need to provide to the As of Dates template.
When we provide the metadata above, our model should look like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13
With our metadata provided and our model complete, we can run dbt to create our As of Dates, as follows:
dbt run -m as_of_date
dbt run -s as_of_date
The resulting As of Date table will look like this: