diff --git a/.circleci/config.yml b/.circleci/config.yml index 7ff3482..2c2bc5e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ version: 2 jobs: build: docker: - - image: circleci/python:3.6.3-stretch + - image: cimg/python:3.9.9 - image: circleci/postgres:9.6.5-alpine-ram steps: @@ -16,7 +16,7 @@ jobs: echo $BIGQUERY_SERVICE_ACCOUNT_JSON > ${HOME}/bigquery-service-key.json - restore_cache: - key: deps1-{{ .Branch }} + key: deps2-{{ .Branch }} - run: name: "Setup dbt" @@ -25,7 +25,7 @@ jobs: . venv/bin/activate pip install --upgrade pip setuptools - pip install dbt + pip install --upgrade dbt-core dbt-bigquery dbt-postgres mkdir -p ~/.dbt cp integration_tests/ci/profiles.yml ~/.dbt/profiles.yml @@ -39,11 +39,11 @@ jobs: . venv/bin/activate echo `pwd` cd integration_tests - dbt --warn-error deps --target bigquery - dbt --warn-error seed --target bigquery --full-refresh - dbt --warn-error compile --target bigquery - dbt --warn-error run --target bigquery - dbt --warn-error test --target bigquery + dbt deps --target bigquery + dbt seed --target bigquery --full-refresh + dbt compile --target bigquery + dbt run --target bigquery + dbt test --target bigquery - run: name: "Run Tests - Postgres" @@ -56,13 +56,13 @@ jobs: command: | . venv/bin/activate cd integration_tests - dbt --warn-error deps --target postgres - dbt --warn-error seed --target postgres --full-refresh - dbt --warn-error compile --target postgres - dbt --warn-error run --target postgres - dbt --warn-error test --target postgres + dbt deps --target postgres + dbt seed --target postgres --full-refresh + dbt compile --target postgres + dbt run --target postgres + dbt test --target postgres - save_cache: - key: deps1-{{ .Branch }} + key: deps2-{{ .Branch }} paths: - "venv" diff --git a/dbt_project.yml b/dbt_project.yml index 74e1341..e33c20d 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -3,9 +3,9 @@ # and underscores. A good package name should reflect your organization's # name or the intended use of these models name: 'dbtplyr' -version: '0.2.1' +version: '0.3.0' config-version: 2 -require-dbt-version: ">=0.19.0" +require-dbt-version: ">=1.0.0" # This setting configures which "profile" dbt uses for this project. profile: 'dbtplyr' diff --git a/integration_tests/packages.yml b/integration_tests/packages.yml index a579c5e..9d32a1a 100644 --- a/integration_tests/packages.yml +++ b/integration_tests/packages.yml @@ -1,4 +1,4 @@ packages: - - package: fishtown-analytics/dbt_utils - version: 0.6.4 - - local: ../ \ No newline at end of file + - package: dbt-labs/dbt_utils + version: 0.8.4 + - local: ../ diff --git a/macros/across.sql b/macros/across.sql index 3b86c7d..235da39 100644 --- a/macros/across.sql +++ b/macros/across.sql @@ -1,4 +1,8 @@ {% macro across(var_list, script_string = '{{var}}', final_comma = false) %} + {{ adapter.dispatch('across', 'dbtplyr') (var_list, script_string, final_comma) }} +{% endmacro %} + +{% macro default__across(var_list, script_string, final_comma) %} {% for v in var_list %} {{ script_string | replace('{{var}}', v) }} @@ -9,6 +13,10 @@ {% endmacro %} {% macro c_across(var_list, script_string) %} + {{ adapter.dispatch('c_across', 'dbtplyr') (var_list, script_string) }} +{% endmacro %} + +{% macro default__c_across(var_list, script_string) %} {% if script_string | length < 2 %} {{ var_list | join(script_string) }} @@ -17,4 +25,4 @@ {{ script_string | replace('{{var}}', vars) }} {% endif %} -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/macros/get_column_names.sql b/macros/get_column_names.sql index 9701ffd..5049904 100644 --- a/macros/get_column_names.sql +++ b/macros/get_column_names.sql @@ -1,4 +1,8 @@ {% macro get_column_names(relation) %} + {{ return( adapter.dispatch('get_column_names', 'dbtplyr')(relation) ) }} +{% endmacro %} + +{% macro default__get_column_names(relation) %} {# if relation is not actually a reference simply pass through #} {# this is useful so downstream functions can accept either list or relation #} diff --git a/macros/get_matches.sql b/macros/get_matches.sql index 643ab49..458fc33 100644 --- a/macros/get_matches.sql +++ b/macros/get_matches.sql @@ -1,4 +1,9 @@ {% macro get_matches(input_list, regex) %} + {{ return( adapter.dispatch('get_matches', 'dbtplyr') (input_list, regex) ) }} +{% endmacro %} + + +{% macro default__get_matches(input_list, regex) %} {% set results_list = [] %} {% for l in input_list %} @@ -9,4 +14,4 @@ {{ return(results_list) }} -{% endmacro %} \ No newline at end of file +{% endmacro %} diff --git a/macros/map.sql b/macros/map.sql index 754989a..d5db054 100644 --- a/macros/map.sql +++ b/macros/map.sql @@ -1,4 +1,8 @@ {% macro map(input_list, fn) %} + {{ return( adapter.dispatch('map', 'dbtplyr') (relation) ) }} +{% endmacro %} + +{% macro default__map(input_list, fn) %} {% set results_list = [] %} {% for l in input_list %} diff --git a/macros/select_helpers.sql b/macros/select_helpers.sql index 5164f5b..4adf308 100644 --- a/macros/select_helpers.sql +++ b/macros/select_helpers.sql @@ -1,4 +1,8 @@ {% macro starts_with(string, relation) %} + {{ return( adapter.dispatch('starts_with', 'dbtplyr') (string, relation) ) }} +{% endmacro %} + +{% macro default__starts_with(string, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = "^" ~ string ~ ".*" %} @@ -8,6 +12,10 @@ {% endmacro %} {% macro ends_with(string, relation) %} + {{ return( adapter.dispatch('ends_with', 'dbtplyr') (string, relation) ) }} +{% endmacro %} + +{% macro default__ends_with(string, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = "^.*" ~ string ~ "$" %} @@ -17,6 +25,10 @@ {% endmacro %} {% macro contains(string, relation) %} + {{ return( adapter.dispatch('contains', 'dbtplyr') (string, relation) ) }} +{% endmacro %} + +{% macro default__contains(string, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = "^.*" ~ string ~ ".*$" %} @@ -26,6 +38,10 @@ {% endmacro %} {% macro not_contains(string, relation) %} + {{ return( adapter.dispatch('not_contains', 'dbtplyr') (string, relation) ) }} +{% endmacro %} + +{% macro default__not_contains(string, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = "^((?!" ~ string ~ ").)*$" %} @@ -35,6 +51,10 @@ {% endmacro %} {% macro one_of(strings, relation) %} + {{ return( adapter.dispatch('one_of', 'dbtplyr') (strings, relation) ) }} +{% endmacro %} + +{% macro default__one_of(strings, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = "^("+ strings|join("|") +")$" %} @@ -44,6 +64,10 @@ {% endmacro %} {% macro not_one_of(strings, relation) %} + {{ return( adapter.dispatch('not_one_of', 'dbtplyr') (strings, relation) ) }} +{% endmacro %} + +{% macro default__not_one_of(strings, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set results = cols | reject('in', strings) %} @@ -52,6 +76,10 @@ {% endmacro %} {% macro matches(string, relation) %} + {{ return( adapter.dispatch('matches', 'dbtplyr') (string, relation) ) }} +{% endmacro %} + +{% macro default__matches(string, relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {%set regex = string %} @@ -60,8 +88,11 @@ {% endmacro %} - {% macro everything(relation) %} + {{ return( adapter.dispatch('everything', 'dbtplyr') (relation) ) }} +{% endmacro %} + +{% macro default__everything(relation) %} {%set cols = dbtplyr.get_column_names(relation) %} {{return(cols)}} @@ -69,6 +100,10 @@ {% endmacro %} {% macro where(fn, relation) %} + {{ return( adapter.dispatch('where', 'dbtplyr') (fn, relation) ) }} +{% endmacro %} + +{% macro default__where(fn, relation) %} {% set cols = adapter.get_columns_in_relation(relation) %} {% set results_list = [] %} diff --git a/macros/where_helpers.sql b/macros/where_helpers.sql index de12af9..89c7406 100644 --- a/macros/where_helpers.sql +++ b/macros/where_helpers.sql @@ -1,4 +1,8 @@ {% macro if_any(var_list, script_string) %} + {{ adapter.dispatch('if_any', 'dbtplyr') (var_list, script_string) }} +{% endmacro %} + +{% macro default__if_any(var_list, script_string) %} {% for v in var_list %} {{ "(" ~ script_string | replace('{{var}}', v) ~ ")" }} @@ -8,6 +12,10 @@ {% endmacro %} {% macro if_all(var_list, script_string) %} + {{ adapter.dispatch('if_all', 'dbtplyr') (var_list, script_string) }} +{% endmacro %} + +{% macro default__if_all(var_list, script_string) %} {% for v in var_list %} {{ "(" ~ script_string | replace('{{var}}', v) ~ ")" }}