Skip to content

Commit

Permalink
Update to dbt 0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
clausherther committed Oct 22, 2020
1 parent d83611a commit 2cb1fb5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions macros/calendar_date/_get_utils_namespaces.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% macro _get_utils_namespaces() %}
{% set override_namespaces = var('dbt_date_dispatch_list', []) %}
{% do return(override_namespaces + ['dbt_date']) %}
{% endmacro %}
16 changes: 8 additions & 8 deletions macros/calendar_date/convert_timezone.sql
Original file line number Diff line number Diff line change
@@ -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 -%}
2 changes: 1 addition & 1 deletion macros/calendar_date/date_part.sql
Original file line number Diff line number Diff line change
@@ -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) -%}
Expand Down
12 changes: 6 additions & 6 deletions macros/calendar_date/day_name.sql
Original file line number Diff line number Diff line change
@@ -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 %}
12 changes: 6 additions & 6 deletions macros/calendar_date/month_name.sql
Original file line number Diff line number Diff line change
@@ -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 %}
8 changes: 4 additions & 4 deletions macros/calendar_date/to_unixtimestamp.sql
Original file line number Diff line number Diff line change
@@ -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 %}
2 changes: 1 addition & 1 deletion macros/get_date_dimension.sql
Original file line number Diff line number Diff line change
@@ -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) %}
Expand Down

0 comments on commit 2cb1fb5

Please sign in to comment.