diff --git a/macros/calendar_date/_get_utils_namespaces.sql b/macros/calendar_date/_get_utils_namespaces.sql new file mode 100644 index 0000000..71931c3 --- /dev/null +++ b/macros/calendar_date/_get_utils_namespaces.sql @@ -0,0 +1,4 @@ +{% macro _get_utils_namespaces() %} + {% set override_namespaces = var('dbt_date_dispatch_list', []) %} + {% do return(override_namespaces + ['dbt_date']) %} +{% endmacro %} diff --git a/macros/calendar_date/convert_timezone.sql b/macros/calendar_date/convert_timezone.sql index 261cd01..17b6747 100644 --- a/macros/calendar_date/convert_timezone.sql +++ b/macros/calendar_date/convert_timezone.sql @@ -1,16 +1,16 @@ -{% macro convert_timezone(column, target_tz=None, source_tz=None) %} +{%- macro convert_timezone(column, target_tz=None, source_tz=None) -%} {%- set target_tz = var("dbt_date:time_zone") if not target_tz else target_tz -%} -{{ adapter_macro('dbt_date.convert_timezone', column, target_tz, source_tz) }} -{% endmacro %} +{{ adapter.dispatch('convert_timezone', packages = dbt_date._get_utils_namespaces()) (column, target_tz, source_tz) }} +{%- endmacro -%} -{% macro default__convert_timezone(column, target_tz, source_tz) %} +{% macro default__convert_timezone(column, target_tz, source_tz) -%} {%- if not source_tz -%} cast(convert_timezone('{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) {%- else -%} cast(convert_timezone('{{ source_tz }}', '{{ target_tz }}', {{ column }}) as {{ dbt_utils.type_timestamp() }}) {%- endif -%} -{% endmacro %} +{%- endmacro -%} -{% macro bigquery__convert_timezone(column, target_tz, source_tz=None) %} - datetime({{ column }}, '{{ target_tz}}') -{% endmacro %} +{%- macro bigquery__convert_timezone(column, target_tz, source_tz=None) -%} + timestamp(datetime({{ column }}, '{{ target_tz}}')) +{%- endmacro -%} diff --git a/macros/calendar_date/date_part.sql b/macros/calendar_date/date_part.sql index 5f9b07c..a12130d 100644 --- a/macros/calendar_date/date_part.sql +++ b/macros/calendar_date/date_part.sql @@ -1,5 +1,5 @@ {% macro date_part(datepart, date) -%} - {{ adapter_macro('dbt_date.date_part', datepart, date) }} + {{ adapter.dispatch('date_part', packages = dbt_date._get_utils_namespaces()) (datepart, date) }} {%- endmacro %} {% macro default__date_part(datepart, date) -%} diff --git a/macros/calendar_date/day_name.sql b/macros/calendar_date/day_name.sql index 75e3eb9..1abe2d7 100644 --- a/macros/calendar_date/day_name.sql +++ b/macros/calendar_date/day_name.sql @@ -1,13 +1,13 @@ -{% macro day_name(date, short=True) -%} - {{ adapter_macro('dbt_date.day_name', date, short) }} +{%- macro day_name(date, short=True) -%} + {{ adapter.dispatch('day_name', packages = dbt_date._get_utils_namespaces()) (date, short) }} {%- endmacro %} -{% macro default__day_name(date, short) -%} -{% set f = 'Dy' if short else 'Day' %} +{%- macro default__day_name(date, short) -%} +{%- set f = 'Dy' if short else 'Day' -%} to_char({{ date }}, '{{ f }}') {%- endmacro %} -{% macro bigquery__day_name(date, short) -%} -{% set f = '%a' if short else '%A' %} +{%- macro bigquery__day_name(date, short) -%} +{%- set f = '%a' if short else '%A' -%} format_date('{{ f }}', cast({{ date }} as date)) {%- endmacro %} diff --git a/macros/calendar_date/month_name.sql b/macros/calendar_date/month_name.sql index dc5ac50..bab021a 100644 --- a/macros/calendar_date/month_name.sql +++ b/macros/calendar_date/month_name.sql @@ -1,13 +1,13 @@ -{% macro month_name(date, short=True) -%} - {{ adapter_macro('dbt_date.month_name', date, short) }} +{%- macro month_name(date, short=True) -%} + {{ adapter.dispatch('month_name', packages = dbt_date._get_utils_namespaces()) (date, short) }} {%- endmacro %} -{% macro default__month_name(date, short) -%} -{% set f = 'MON' if short else 'MONTH' %} +{%- macro default__month_name(date, short) -%} +{%- set f = 'MON' if short else 'MONTH' -%} to_char({{ date }}, '{{ f }}') {%- endmacro %} -{% macro bigquery__month_name(date, short) -%} -{% set f = '%b' if short else '%B' %} +{%- macro bigquery__month_name(date, short) -%} +{%- set f = '%b' if short else '%B' -%} format_date('{{ f }}', cast({{ date }} as date)) {%- endmacro %} diff --git a/macros/calendar_date/to_unixtimestamp.sql b/macros/calendar_date/to_unixtimestamp.sql index 59b0d64..ec3319a 100644 --- a/macros/calendar_date/to_unixtimestamp.sql +++ b/macros/calendar_date/to_unixtimestamp.sql @@ -1,11 +1,11 @@ -{% macro to_unixtimestamp(timestamp) -%} - {{ adapter_macro('dbt_date.to_unixtimestamp', timestamp) }} +{%- macro to_unixtimestamp(timestamp) -%} + {{ adapter.dispatch('to_unixtimestamp', packages = dbt_date._get_utils_namespaces()) (timestamp) }} {%- endmacro %} -{% macro default__to_unixtimestamp(timestamp) -%} +{%- macro default__to_unixtimestamp(timestamp) -%} {{ dbt_date.date_part('epoch_seconds', timestamp) }} {%- endmacro %} -{% macro bigquery__to_unixtimestamp(timestamp) -%} +{%- macro bigquery__to_unixtimestamp(timestamp) -%} unix_seconds({{ timestamp }}) {%- endmacro %} diff --git a/macros/get_date_dimension.sql b/macros/get_date_dimension.sql index d25eaa6..55762ba 100644 --- a/macros/get_date_dimension.sql +++ b/macros/get_date_dimension.sql @@ -1,5 +1,5 @@ {% macro get_date_dimension(start_date, end_date) %} -{{ adapter_macro('dbt_date.get_date_dimension', start_date, end_date) }} + {{ adapter.dispatch('get_date_dimension', packages = dbt_date._get_utils_namespaces()) (start_date, end_date) }} {% endmacro %} {% macro default__get_date_dimension(start_date, end_date) %}