Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duckdb support #271

Merged
merged 7 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
DBT_PROFILES_DIR: ./integration_tests/ci
DBT_PROJECT_DIR: ./integration_tests
BIGQUERY_SERVICE_KEY_PATH: "/home/circleci/bigquery-service-key.json"
DBT_VERSION: 1.4.1
DBT_VERSION: 1.6.0

steps:
- checkout
Expand All @@ -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 @@ -76,6 +76,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
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
10 changes: 7 additions & 3 deletions integration_tests/models/schema_tests/timeseries_hourly.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{{ dbt_date.date_spine('hour',
start_date=dbt_date.n_days_ago(10),
end_date=dbt_date.tomorrow()
{% set end_date = modules.datetime.datetime.today().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set start_date = (end_date - modules.datetime.timedelta(days=10)) %}

{{ dbt_date.get_base_dates(
start_date=start_date,
end_date=end_date,
datepart="hour"
)
}}
6 changes: 6 additions & 0 deletions macros/math/rand.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@
random()

{%- endmacro -%}

{% macro duckdb__rand() -%}

random()

{%- endmacro -%}
10 changes: 8 additions & 2 deletions macros/regex/regexp_instr.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ coalesce(array_length((select regexp_matches({{ source_value }}, '{{ regexp }}',
regexp_instr({{ source_value }}, '{{ regexp }}', {{ position }}, {{ occurrence }}, 0, '{{ flags }}')
{% endmacro %}

{% macro duckdb__regexp_instr(source_value, regexp, position, occurrence, is_raw, flags) %}
{% if flags %}{{ dbt_expectations._validate_flags(flags, 'ciep') }}{% endif %}
regexp_matches({{ source_value }}, '{{ regexp }}', '{{ flags }}')
{% endmacro %}


{% macro _validate_flags(flags, alphabet) %}
{% for flag in flags %}
{% if flag not in alphabet %}
Expand Down Expand Up @@ -74,7 +80,7 @@ regexp_instr({{ source_value }}, '{{ regexp }}', {{ position }}, {{ occurrence }
{% if not is_match %}
{# Using raise_compiler_error causes disabled tests with invalid flags to fail compilation #}
{{ exceptions.warn(
"flags " ~ flags ~ " isn't a valid re2 flag pattern"
"flags " ~ flags ~ " isn't a valid re2 flag pattern"
) }}
{% endif %}
{% endmacro %}
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/utils/datatypes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@
{% macro postgres__type_datetime() -%}
timestamp without time zone
{%- endmacro %}

{% macro duckdb__type_datetime() -%}
timestamp
{%- endmacro %}
2 changes: 1 addition & 1 deletion packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages:
- package: calogica/dbt_date
version: [">=0.7.0", "<0.8.0"]
version: [">=0.8.0", "<0.9.0"]