You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01_Macro_Instructions/22_Business_Vault/24_Snapshot_Control/24_snapshot_control_v0.md
+50-23Lines changed: 50 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,29 +8,58 @@ title: Snapshot Control v0
8
8
9
9
---
10
10
11
-
This macro creates a snapshot table to control snapshot-based tables like PITs and Bridges. The snapshot table will hold daily snapshots starting at a specific start_date and has a configurable daytime. Usual application would involve creating one snapshot table per Data Vault environment, and therefore creating one dbt model using this macro. The model needs to be scheduled daily, with a execution time that matches your desired snapshot time, since the macro automatically inserts all snapshots until the current day, no matter which time it is, and a snapshot for 08:00:00 should be calculated at that time. So if the snapshot table is configured to have a ‘daily_snapshot_time’ of ’07:00:00′, all snapshots in the table will have the timestamp ’07:00:00′. Therefore you need to schedule the building of the snapshot table also to ’07:00:00′.
11
+
This macro creates a snapshot table to control snapshot-based tables like PITs and Bridges. The snapshot table will hold daily snapshots starting at a specific start_date and has a configurable daytime. Usual application would involve creating one snapshot table per Data Vault environment, and therefore creating one dbt model using this macro. The model needs to be scheduled daily, with an execution time that matches your desired snapshot time, since the macro automatically inserts all snapshots until the current day, no matter which time it is, and a snapshot for 08:00:00 should be calculated at that time. So if the snapshot table is configured to have a `daily_snapshot_time` of `07:00:00`, all snapshots in the table will have the timestamp `07:00:00`. Therefore you need to schedule the building of the snapshot table also to `07:00:00`.
12
12
13
13
In addition to the actual snapshot-datetimestamp (sdts), the macro generates the following columns:
14
14
15
-
| Column | Data Type | Explanation |
16
-
|------------------|-----------|-------------|
17
-
| replacement_sdts | timestamp | Allows users to replace a sdts with another one, without having to update the actual sdts column. By default this column is filled with the regular sdts. |
18
-
| caption | string | Allows users to title their snapshots. Examples would be something like: 'Christmas 2022', or 'End-of-year report 2021'. By default this is filled with 'Snapshot \{sdts\}', holding the respective sdts. |
19
-
| is_hourly | boolean | Captures if the time of a sdts is on an exact hour, meaning minutes=0 and seconds=0. All sdts created by this macro are daily and therefore always hourly, but this column enables future inserts of custom, user-defined sdts. |
20
-
| is_daily | boolean | Captures if the time of a sdts is on exactly midnight, meaning hours=0, minutes=0 and seconds=0. This depends on your desired daily_snapshot_time, but is not used by the downstream macros, and just generates additional metadata for potential future use. |
21
-
| is_weekly | boolean | Captures if the day of the week of a sdts is Monday. |
22
-
| is_monthly | boolean | Captures if a sdts is the first day of a month. |
23
-
| is_end_of_month | boolean | Captures if a sdts is the last day of a month. |
24
-
| is_quarterly | boolean | Captures if a sdts is the first day of a quarter. |
25
-
| is_yearly | boolean | Captures if a sdts is the first day of a year. |
26
-
| is_end_of_year | boolean | Captures if a sdts is the last day of a year. |
27
-
| comment | string | Allows users to write custom comments for each sdts. By default this column is set to NULL. |
28
-
29
-
| Parameters | Data Type | Required | Default Value | Explanation |
| start_date | date | mandatory | – | Defines the earliest date that should be available inside the snapshot_table. The format of this date must be 'YYYY-MM-DD'. |
32
-
| daily_snapshot_time | time | mandatory | – | Defines the time that your daily snapshots should have. Usually this is either something right before daily business starts, or after daily business is over. Needs to be in the format 'hh:mm:ss'. |
33
-
| sdts_alias | string | optional | datavault4dbt.sdts_alias | Defines the name of the snapshot date timestamp column inside the snapshot_table. |
15
+
| Column | Data Type | Explanation |
16
+
|---|---|---|
17
+
| replacement_sdts | timestamp | Allows users to replace an sdts with another one, without having to update the actual sdts column. By default this column is filled with the regular sdts. |
18
+
| caption | string | Allows users to title their snapshots. Examples would be something like: 'Christmas 2022', or 'End-of-year report 2021'. By default this is filled with 'Snapshot \{sdts\}', holding the respective sdts. |
19
+
| is_hourly | boolean | Captures if the time of an sdts is on an exact hour, meaning minutes=0 and seconds=0. All sdts created by this macro are daily and therefore always hourly, but this column enables future inserts of custom, user-defined sdts. |
20
+
| is_daily | boolean | Captures if the time of an sdts is on exactly midnight, meaning hours=0, minutes=0 and seconds=0. This depends on your desired daily_snapshot_time, but is not used by the downstream macros, and just generates additional metadata for potential future use. |
21
+
| is_beginning_of_week | boolean | Captures if a sdts is the first day of the week. This is fully configurable via the `datavault4dbt.first_day_of_week` variable. |
22
+
| is_end_of_week | boolean | Captures if a sdts is the last day of the week, automatically calculated based on your configured first day of the week. |
23
+
| is_beginning_of_month | boolean | Captures if a sdts is the first day of a month. |
24
+
| is_end_of_month | boolean | Captures if a sdts is the last day of a month. |
25
+
| is_beginning_of_quarter | boolean | Captures if a sdts is the first day of a quarter. |
26
+
| is_end_of_quarter | boolean | Captures if a sdts is the last day of a quarter. |
27
+
| is_beginning_of_year | boolean | Captures if a sdts is the first day of a year. |
28
+
| is_end_of_year | boolean| Captures if a sdts is the last day of a year. |
29
+
| comment | string | Allows users to write custom comments for each sdts. By default this column is set to NULL. |
30
+
31
+
32
+
### Macro Parameters
33
+
34
+
| Parameters | Data Type | Required | Default Value | Explanation |
35
+
|---|---|---|---|---|
36
+
| start_date | date | mandatory | – | Defines the earliest date that should be available inside the snapshot_table. The format of this date must be 'YYYY-MM-DD'. |
37
+
| daily_snapshot_time | time | mandatory | – | Defines the time that your daily snapshots should have. Usually this is either something right before daily business starts, or after daily business is over. Needs to be in the format 'hh:mm:ss'. |
38
+
| sdts_alias | string | optional | datavault4dbt.sdts_alias | Defines the name of the snapshot date timestamp column inside the snapshot_table. |
39
+
40
+
41
+
---
42
+
43
+
## DAY OF WEEK ADAPTER REFERENCE MATRIX
44
+
45
+
Because different database dialects use different standards and functions for extracting the day of the week, configuring your `datavault4dbt.first_day_of_week` variable requires knowing how your specific target database behaves natively.
46
+
47
+
Use the table below to determine the correct integer to input for your target database in your `dbt_project.yml` based on whether you want your weeks to start on Sunday or Monday.
- **start_date**: The parameter start_date has to be in the format ‘YYYY-MM-DD’. With the start_date set to ‘2015-01-01’, the snapshot table would hold daily snapshots beginning at 2015.
Copy file name to clipboardExpand all lines: docs/01_Macro_Instructions/22_Business_Vault/24_Snapshot_Control/25_snapshot_control_v1.md
+38-28Lines changed: 38 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,30 +8,40 @@ title: Snapshot Control v1
8
8
9
9
---
10
10
11
-
This macro creates a view that extends an existing control_snap_v0 table by dynamically changing information. These information include a logic to implement logarithmic snapshots. That means that the further I look into the past, the more coarsely the snapshots should be granulated.
11
+
This macro creates a view that extends an existing `control_snap_v0` table by dynamically adding information. This information includes a logic to implement logarithmic snapshots. That means that the further I look into the past, the more coarsely the snapshots should be granulated.
12
12
13
13
For example, I want to keep daily snapshots for the past 30 days, but I am not interested in daily snapshots for the past 10 years, and therefore I only keep weekly snapshots for the past 6 months, monthly snapshots for the past 3 years, and yearly snapshots forever. This procedure strongly reduces the number of active snapshots, and therefore also the number of rows, and the required computation inside all PITs and Bridges. This logic is optional and would be captured in a boolean column called `is_active`.
14
14
15
-
Whenever a logarithmic snapshot logic is used and picked up by PIT tables, a logic is required that deletes records out of PIT tables, that are no longer active. For this, a post_hook called “clean_up_pit” is provided in this package, that should be applied for each PIT table.
15
+
Whenever a logarithmic snapshot logic is used and picked up by PIT tables, a logic is required that deletes records out of PIT tables that are no longer active. For this, a post_hook called `clean_up_pit` is provided in this package, that should be applied for each PIT table.
16
16
17
-
In addition to that, a few other dynamic columns are generated:
17
+
In addition to inheriting the core columns (`sdts`, `replacement_sdts`, `caption`, `is_hourly`, `is_daily`, `comment`) from the `control_snap_v0` view, the following dynamic and pass-through columns are generated:
| is_latest | boolean | Captures if a sdts is the latest one inside the snapshot table. There is always only one snapshot inside the view that has TRUE here. |
22
-
| is_current_year | boolean | Captures if a sdts is part of the current calendar year. |
23
-
| is_last_year | boolean | Captures if a sdts is part of the last calendar year. |
24
-
| is_rolling_year | boolean | Captures if a sdts is inside the past year, starting from the current date. |
25
-
| is_last_rolling_year | boolean | Captures if a sdts is inside the range that starts two years ago (from the current date) and ranges until one year ago (from the current date). |
19
+
| Column | Data Type | Explanation |
20
+
|---|---|---|
21
+
| snapshot_trigger_column | boolean | Defaults to `is_active`. Captures if a snapshot is considered "active" based on the logarithmic logic provided. If no logic is provided, this defaults to TRUE for all snapshots. |
22
+
| is_latest | boolean | Captures if a sdts is the latest one inside the snapshot table. There is always exactly one snapshot inside the view that evaluates to TRUE here. |
23
+
| is_beginning_of_week | boolean | Inherited from v0. Captures if a sdts is the first day of the week based on your global config. |
24
+
| is_end_of_week | boolean | Inherited from v0. Captures if a sdts is the last day of the week. |
25
+
| is_beginning_of_month | boolean | Inherited from v0. Captures if a sdts is the first day of a month. |
26
+
| is_end_of_month | boolean | Inherited from v0. Captures if a sdts is the last day of a month. |
27
+
| is_beginning_of_quarter | boolean | Inherited from v0. Captures if a sdts is the first day of a quarter. |
28
+
| is_end_of_quarter | boolean | Inherited from v0. Captures if a sdts is the last day of a quarter. |
29
+
| is_beginning_of_year | boolean | Inherited from v0. Captures if a sdts is the first day of a year. |
30
+
| is_end_of_year | boolean | Inherited from v0. Captures if a sdts is the last day of a year. |
31
+
| is_current_year | boolean | Captures if a sdts is part of the current calendar year. |
32
+
| is_last_year | boolean | Captures if a sdts is part of the last calendar year. |
33
+
| is_rolling_year | boolean | Captures if a sdts is inside the past year, starting from the current date. |
34
+
| is_last_rolling_year | boolean | Captures if a sdts is inside the range that starts two years ago (from the current date) and ranges until one year ago (from the current date). |
26
35
27
-
| Parameters | Data Type | Required | Default Value | Explanation |
| log_logic | dictionary | optional | None | Defining the desired durations of each granularity. Available granularities are 'daily', 'weekly', 'monthly', 'end_of_month', 'quarterly', 'yearly' and 'end_of_year'. For each granularity the duration can be defined as an integer and the time unit for that duration. The units include (in BigQuery): DAY, WEEK, MONTH, QUARTER, YEAR. Besides defining a duration and a unit for each granularity, there is also the option to set a granularity to 'forever'. E.g. reporting requires daily snapshots for 3 months, and after that the monthly snapshots should be kept forever. If log_logic is not set, no logic will be applied, and all snapshots will stay active. The other dynamic columns are calculated anyway. The duration is always counted from the current date. |
34
-
| sdts_alias | string | optional | datavault4dbt.sdts_alias | Defines the name of the snapshot date timestamp column inside the snapshot_table. |
38
+
| Parameters | Data Type | Required | Default Value | Explanation |
39
+
|---|---|---|---|---|
40
+
| control_snap_v0 | string | mandatory | – | The name of the underlying version 0 control snapshot table. Needs to be available as a dbt model. |
41
+
| log_logic | dictionary | optional | None | Defines the desired durations of each granularity. Available granularities check against the V0 flags and include: `daily`, `weekly`, `monthly`, `yearly`. For each granularity, the duration can be defined as an integer and the time unit for that duration. The units include: DAY, MONTH, YEAR, etc. Besides defining a duration and a unit, there is also the option to set a granularity to `forever: TRUE`. E.g. reporting requires daily snapshots for 3 months, and after that the monthly snapshots should be kept forever. If `log_logic` is not set, no logic will be applied, and all snapshots will stay active. The duration is always counted from the current date. |
42
+
| sdts_alias | string | optional | datavault4dbt.sdts_alias | Defines the name of the snapshot date timestamp column inside the snapshot_table. |
43
+
44
+
---
35
45
36
46
## EXAMPLE 1
37
47
@@ -41,17 +51,17 @@ In addition to that, a few other dynamic columns are generated:
Copy file name to clipboardExpand all lines: docs/26_General_Usage_Notes/29_Global_Variables/29_Global_Variables.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@ All the following variables are **prefixed with `datavault4dbt`**.
29
29
| include_business_objects_before_appearance | Ref Table | If a Ref_Hub entry should appear in the ref_table (snapshot based), even if the snapshot date is before the first appearance of that business object. |
30
30
| enable_static_analysis_overwrite | All macros | Relevant for Fusion compatibility. For more info, see here. |
31
31
| multi_source_models_execution_aware_loading | Multi source entities | Whether multi source entities should respect the dbt command to reduce runtimes. |
32
+
| first_day_of_week | Snapshot Table | A mapping dictionary that defines the integer representation of the first day of the week (Sunday vs. Monday) for each specific database adapter. For the full configuration matrix, see [Snapshot Control v0](../24_Snapshot_Control/24_snapshot_control_v0.md). |
0 commit comments