Skip to content

Commit

Permalink
Merge pull request #249 from ScalefreeCOM/add-macros-for-global-begin…
Browse files Browse the repository at this point in the history
…ning-and-end-of-all-times-dates

Add macros for global beginning and end of all times dates
  • Loading branch information
tkiehn authored Sep 4, 2024
2 parents aa7716d + 3f44edf commit edceed4
Show file tree
Hide file tree
Showing 5 changed files with 491 additions and 22 deletions.
6 changes: 3 additions & 3 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ vars:
datavault4dbt.end_of_all_times: {"bigquery":"8888-12-31T23-59-59","snowflake":"8888-12-31T23:59:59", "exasol": "8888-12-31 23:59:59", "postgres": "8888-12-31 23:59:59", "redshift": "8888-12-31 23:59:59", "synapse": "8888-12-31T23:59:59"}
datavault4dbt.timestamp_format: {"bigquery":"%Y-%m-%dT%H-%M-%S","snowflake":"YYYY-MM-DDTHH24:MI:SS", "exasol": "YYYY-mm-dd HH:MI:SS", "postgres": "YYYY-MM-DD HH24:MI:SS", "redshift": "YYYY-MM-DD HH24:MI:SS", "synapse": 126}

#datavault4dbt.beginning_of_all_times_date: {"bigquery":"0001-01-01","snowflake":"0001-01-01", "exasol": "0001-01-01", "postgres": "0001-01-01", "redshift": "0001-01-01", "synapse": "1901-01-01"}
#datavault4dbt.end_of_all_times_date: {"bigquery":"8888-12-31","snowflake":"8888-12-31", "exasol": "8888-12-31", "postgres": "8888-12-31", "redshift": "8888-12-31", "synapse": "8888-12-31"}
#datavault4dbt.date_format: {"bigquery":"%Y-%m-%d","snowflake":"YYYY-MM-DD", "exasol": "YYYY-mm-dd", "postgres": "YYYY-MM-DD", "redshift": "YYYY-MM-DD", "synapse": "yyyy-MM-dd"}
datavault4dbt.beginning_of_all_times_date: {"bigquery":"0001-01-01","snowflake":"0001-01-01", "exasol": "0001-01-01", "postgres": "0001-01-01", "redshift": "0001-01-01", "synapse": "1901-01-01"}
datavault4dbt.end_of_all_times_date: {"bigquery":"8888-12-31","snowflake":"8888-12-31", "exasol": "8888-12-31", "postgres": "8888-12-31", "redshift": "8888-12-31", "synapse": "8888-12-31"}
datavault4dbt.date_format: {"bigquery":"%Y-%m-%d","snowflake":"YYYY-MM-DD", "exasol": "YYYY-mm-dd", "postgres": "YYYY-MM-DD", "redshift": "YYYY-MM-DD", "synapse": "yyyy-MM-dd"}

datavault4dbt.default_unknown_rsrc: 'SYSTEM'
datavault4dbt.default_error_rsrc: 'ERROR'
Expand Down
155 changes: 155 additions & 0 deletions macros/supporting/beginning_of_all_times_date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{%- macro beginning_of_all_times_date() %}

{{ return( adapter.dispatch('beginning_of_all_times_date', 'datavault4dbt')() ) }}

{%- endmacro -%}


{%- macro default__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'bigquery' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['bigquery'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (bigquery) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}


{%- macro snowflake__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'snowflake' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['snowflake'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (snowflake) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}


{%- macro exasol__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'exasol' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['exasol'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (exasol) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}


{%- macro synapse__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'synapse' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['synapse'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (synapse) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "1901-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "1901-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}


{%- macro postgres__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'postgres' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['postgres'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (postgres) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}


{%- macro redshift__beginning_of_all_times_date() %}

{%- set global_var = var('datavault4dbt.beginning_of_all_times_date', none) -%}
{%- set beginning_of_all_times_date = '' -%}

{%- if global_var is mapping -%}
{%- if 'redshift' in global_var.keys()|map('lower') -%}
{% set beginning_of_all_times_date = global_var['redshift'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.beginning_of_all_times_date' to a dictionary, but have not included the adapter you use (redshift) as a key. Applying the default value.") -%}
{% endif %}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set beginning_of_all_times_date = global_var -%}
{%- else -%}
{%- set beginning_of_all_times_date = "0001-01-01" -%}
{%- endif -%}

{{ return(beginning_of_all_times_date) }}

{%- endmacro -%}
154 changes: 154 additions & 0 deletions macros/supporting/date_format.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{%- macro date_format() %}

{{ return(adapter.dispatch('date_format', 'datavault4dbt')()) }}

{%- endmacro -%}


{%- macro default__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'bigquery' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['bigquery'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (bigquery) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "%Y-%m-%d" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "%Y-%m-%d" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}


{%- macro snowflake__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'snowflake' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['snowflake'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (snowflake) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "YYYY-MM-DD" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "YYYY-MM-DD" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}


{%- macro exasol__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'exasol' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['exasol'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (exasol) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "YYYY-mm-dd" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "YYYY-mm-dd" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}


{%- macro synapse__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'synapse' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['synapse'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (synapse) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "yyyy-MM-dd" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "yyyy-MM-dd" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}


{%- macro postgres__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'postgres' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['postgres'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (postgres) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "YYYY-MM-DD" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "YYYY-MM-DD" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}

{%- macro redshift__date_format() %}

{%- set global_var = var('datavault4dbt.date_format', none) -%}
{%- set date_format = '' -%}

{%- if global_var is mapping -%}
{%- if 'redshift' in global_var.keys()|map('lower') -%}
{% set date_format = global_var['redshift'] %}
{%- else -%}
{%- if execute -%}
{%- do exceptions.warn("Warning: You have set the global variable 'datavault4dbt.date_format' to a dictionary, but have not included the adapter you use (redshift) as a key. Applying the default value.") -%}
{% endif %}
{%- set date_format = "YYYY-MM-DD" -%}
{% endif %}
{%- elif global_var is not mapping and datavault4dbt.is_something(global_var) -%}
{%- set date_format = global_var -%}
{%- else -%}
{%- set date_format = "YYYY-MM-DD" -%}
{%- endif -%}

{{ return(date_format) }}

{%- endmacro -%}
Loading

0 comments on commit edceed4

Please sign in to comment.