Skip to content

Commit

Permalink
Add support for dbt-duckdb to the dbt_date package (#105)
Browse files Browse the repository at this point in the history
* Add support for dbt-duckdb to the dbt_date package

* fix silly typo

* The path arg is required in the profile for dbt-duckdb 1.4.1

* Add DuckDB support to the README
  • Loading branch information
jwills authored Aug 6, 2023
1 parent f801db7 commit cc5c560
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python3 -m venv venv
. venv/bin/activate
pip install -U pip setuptools wheel
pip install dbt-core==$DBT_VERSION dbt-postgres==$DBT_VERSION dbt-bigquery==$DBT_VERSION dbt-snowflake==$DBT_VERSION
pip install dbt-core==$DBT_VERSION dbt-postgres==$DBT_VERSION dbt-bigquery==$DBT_VERSION dbt-snowflake==$DBT_VERSION dbt-duckdb==$DBT_VERSION
- run:
name: Install dbt dependencies
Expand Down Expand Up @@ -65,6 +65,12 @@ jobs:
. venv/bin/activate
dbt build -t snowflake --project-dir $DBT_PROJECT_DIR
- run:
name: "Run Tests - DuckDB"
command: |
. venv/bin/activate
dbt build -t duckdb --project-dir $DBT_PROJECT_DIR
- store_artifacts:
path: ./logs

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ This package supports:
* Postgres
* Snowflake
* BigQuery
* DuckDB

For other platforms, you will have to include a shim package for the platform, such as `spark-utils`, or `tsql-utils`.

Expand Down
4 changes: 4 additions & 0 deletions integration_tests/ci/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ integration_tests:
schema: "{{ env_var('SNOWFLAKE_TEST_SCHEMA') }}"
threads: 10

duckdb:
type: duckdb
path: ":memory:"

target: postgres
6 changes: 4 additions & 2 deletions integration_tests/macros/get_test_dates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,7 @@ select
'2021-06-07 14:35:20.000000 -0000']) }}
{%- endmacro %}



{% macro duckdb__get_test_timestamps() -%}
{{ return(['2021-06-07 07:35:20.000000',
'2021-06-07 14:35:20.000000']) }}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/convert_timezone.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ cast(
{%- macro redshift__convert_timezone(column, target_tz, source_tz) -%}
{{ return(dbt_date.default__convert_timezone(column, target_tz, source_tz)) }}
{%- endmacro -%}

{% macro duckdb__convert_timezone(column, target_tz, source_tz) -%}
{{ return(dbt_date.postgres__convert_timezone(column, target_tz, source_tz)) }}
{%- endmacro -%}
8 changes: 8 additions & 0 deletions macros/calendar_date/day_name.sql
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@
{%- set f = 'FMDy' if short else 'FMDay' -%}
to_char({{ date }}, '{{ f }}')
{%- endmacro %}

{%- macro duckdb__day_name(date, short) -%}
{%- if short -%}
substr(dayname({{ date }}), 1, 3)
{%- else -%}
dayname({{ date }})
{%- endif -%}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/day_of_week.sql
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@
{%- endif -%}

{%- endmacro %}

{%- macro duckdb__day_of_week(date, isoweek) -%}
{{ return(dbt_date.postgres__day_of_week(date, isoweek)) }}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/iso_week_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ cast({{ dbt_date.date_part(week_type, date) }} as {{ dbt.type_int() }})
-- postgresql week is isoweek, the first week of a year containing January 4 of that year.
{{ dbt_date._iso_week_of_year(date, 'week') }}
{%- endmacro %}

{%- macro duckdb__iso_week_of_year(date) -%}
{{ return(dbt_date.postgres__iso_week_of_year(date)) }}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/iso_week_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ cast({{ dbt.date_trunc(week_type, date) }} as date)
{%- macro postgres__iso_week_start(date) -%}
{{ dbt_date._iso_week_start(date, 'week') }}
{%- endmacro %}

{%- macro duckdb__iso_week_start(date) -%}
{{ return(dbt_date.postgres__iso_week_start(date)) }}
{%- endmacro %}
9 changes: 9 additions & 0 deletions macros/calendar_date/month_name.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@
{%- set f = 'FMMon' if short else 'FMMonth' -%}
to_char({{ date }}, '{{ f }}')
{%- endmacro %}


{%- macro duckdb__month_name(date, short) -%}
{%- if short -%}
substr(monthname({{ date }}), 1, 3)
{%- else -%}
monthname({{ date }})
{%- endif -%}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/week_end.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
{%- set dt = dbt_date.week_start(date) -%}
{{ dbt_date.n_days_away(6, dt) }}
{%- endmacro %}

{%- macro duckdb__week_end(date) -%}
{{ return(dbt_date.postgres__week_end(date)) }}
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/week_of_year.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ cast({{ dbt_date.date_part('week', date) }} as {{ dbt.type_int() }})
WW = the first week starts on the first day of the year #}
cast(to_char({{ date }}, 'WW') as {{ dbt.type_int() }})
{%- endmacro %}

{%- macro duckdb__week_of_year(date) -%}
cast(ceil(dayofyear({{ date }}) / 7) as int)
{%- endmacro %}
4 changes: 4 additions & 0 deletions macros/calendar_date/week_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ cast({{ dbt.date_trunc('week', date) }} as date)
-- Sunday as week start date
cast({{ dbt.dateadd('day', -1, dbt.date_trunc('week', dbt.dateadd('day', 1, date))) }} as date)
{%- endmacro %}

{%- macro duckdb__week_start(date) -%}
{{ return(dbt_date.postgres__week_start(date)) }}
{%- endmacro %}

0 comments on commit cc5c560

Please sign in to comment.