-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
223 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
macros/materialisations/period_mat_helpers/check_datediff.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) Business Thinking Ltd. 2019-2023 | ||
* This software includes code developed by the dbtvault Team at Business Thinking Ltd. Trading as Datavault | ||
*/ | ||
|
||
{%- macro check_num_periods(start_date, stop_date, period) -%} | ||
|
||
{% set num_periods = adapter.dispatch('check_num_periods', | ||
'dbtvault')(start_date=start_date, | ||
stop_date=stop_date, | ||
period=period) %} | ||
|
||
{%- if num_periods > 100000 -%} | ||
{%- set error_message -%} | ||
'Max iterations is 100,000. Consider using a different datepart value (e.g. day) | ||
or loading data for a shorter time period. | ||
vault_insert_by materialisations are not intended for this purpose, | ||
please see https://dbtvault.readthedocs.io/en/latest/materialisations/' | ||
{%- endset -%} | ||
|
||
{{- exceptions.raise_compiler_error(error_message) -}} | ||
{%- endif -%} | ||
|
||
{% do return(num_periods) %} | ||
|
||
{%- endmacro %} | ||
|
||
{% macro default__check_num_periods(start_date, stop_date, period) %} | ||
|
||
{% set num_periods_check_sql %} | ||
SELECT {{ datediff('start_timestamp', 'stop_timestamp', period) }} AS NUM_PERIODS | ||
FROM | ||
(SELECT CAST('{{ start_date }}' AS {{ dbt.type_timestamp() }}) AS start_timestamp, | ||
CAST(NULLIF('{{ stop_date | lower }}', 'none') AS {{ dbt.type_timestamp() }}) AS stop_timestamp) | ||
{% endset %} | ||
{% set num_periods_dict = dbtvault.get_query_results_as_dict(num_periods_check_sql) %} | ||
{% set num_periods = num_periods_dict['NUM_PERIODS'][0] | int %} | ||
|
||
{% do return(num_periods) %} | ||
|
||
{% endmacro %} | ||
|
||
{% macro sqlserver__check_num_periods(start_date, stop_date, period) %} | ||
|
||
{% set num_periods_check_sql %} | ||
SELECT DATEDIFF_BIG({{ period }}, CAST('{{ start_date }}' AS DATETIME2), | ||
CAST(NULLIF('{{ stop_date | lower }}', 'none') AS DATETIME2)) AS NUM_PERIODS | ||
{% endset %} | ||
{% set num_periods_dict = dbtvault.get_query_results_as_dict(num_periods_check_sql) %} | ||
{% set num_periods = num_periods_dict['NUM_PERIODS'][0] | int %} | ||
|
||
{% do return(num_periods) %} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{%- macro date_ghost(date_type, alias) -%} | ||
{{ adapter.dispatch('date_ghost', 'dbtvault')(date_type=date_type, alias=alias) }} | ||
{%- endmacro -%} | ||
|
||
{%- macro default__date_ghost(date_type, alias=none) -%} | ||
|
||
{%- if date_type == 'date' -%} | ||
{{ dbtvault.cast_date('1900-01-01', as_string=true, datetime=false, alias=alias) }} | ||
{%- else -%} | ||
{{ dbtvault.cast_date('1900-01-01 00:00:00', as_string=true, datetime=true, alias=alias, date_type=date_type) }} | ||
{%- endif -%} | ||
|
||
{%- endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.