Skip to content

Commit

Permalink
Merge pull request #5 from calogica/update-dbt-18
Browse files Browse the repository at this point in the history
Update to dbt 0.18.x
  • Loading branch information
clausherther authored Oct 25, 2020
2 parents d83611a + 43aeaad commit 203d107
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 33 deletions.
14 changes: 9 additions & 5 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
name: 'dbt_date'
version: '0.1'
version: '0.2'

config-version: 2

target-path: "target"
clean-targets: ["target", "dbt_modules"]
macro-paths: ["macros"]
log-path: "logs"

require-dbt-version: ">=0.14.0"
profile: dev
require-dbt-version: [">=0.18.0", "<0.19.0"]
profile: integration_tests

quoting:
identifier: false
schema: false

vars:
'dbt_date:time_zone': 'America/Los_Angeles'

models:
vars:
'dbt_date:time_zone': 'America/Los_Angeles'
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/fiscal_date/get_fiscal_year_dates.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro get_fiscal_year_dates(dates, year_end_month=12, week_start_day=1, shift_year=1) %}
{{ adapter_macro('dbt_date.get_fiscal_year_dates', dates, year_end_month, week_start_day, shift_year) }}
{{ adapter.dispatch('get_fiscal_year_dates', packages = dbt_date._get_utils_namespaces()) (dates, year_end_month, week_start_day, shift_year) }}
{% endmacro %}

{% macro default__get_fiscal_year_dates(dates, year_end_month, week_start_day, shift_year) %}
Expand Down
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
2 changes: 1 addition & 1 deletion packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages:
- package: fishtown-analytics/dbt_utils
version: [">=0.2.0", "<0.3.0"]
version: [">=0.6.0", "<0.7.0"]

0 comments on commit 203d107

Please sign in to comment.