Skip to content

Commit

Permalink
Merge pull request #10 from BeadW/upgrade-macros
Browse files Browse the repository at this point in the history
Modified macros to respect namespaces.
  • Loading branch information
emilyriederer authored May 1, 2022
2 parents c34a98f + cd2070e commit bf3573f
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 22 deletions.
28 changes: 14 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/packages.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
packages:
- package: fishtown-analytics/dbt_utils
version: 0.6.4
- local: ../
- package: dbt-labs/dbt_utils
version: 0.8.4
- local: ../
10 changes: 9 additions & 1 deletion macros/across.sql
Original file line number Diff line number Diff line change
@@ -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) }}
Expand All @@ -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) }}
Expand All @@ -17,4 +25,4 @@
{{ script_string | replace('{{var}}', vars) }}
{% endif %}

{% endmacro %}
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/get_column_names.sql
Original file line number Diff line number Diff line change
@@ -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 #}
Expand Down
7 changes: 6 additions & 1 deletion macros/get_matches.sql
Original file line number Diff line number Diff line change
@@ -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 %}
Expand All @@ -9,4 +14,4 @@

{{ return(results_list) }}

{% endmacro %}
{% endmacro %}
4 changes: 4 additions & 0 deletions macros/map.sql
Original file line number Diff line number Diff line change
@@ -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 %}
Expand Down
37 changes: 36 additions & 1 deletion macros/select_helpers.sql
Original file line number Diff line number Diff line change
@@ -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 ~ ".*" %}
Expand All @@ -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 ~ "$" %}
Expand All @@ -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 ~ ".*$" %}
Expand All @@ -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 ~ ").)*$" %}
Expand All @@ -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("|") +")$" %}
Expand All @@ -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) %}
Expand All @@ -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 %}
Expand All @@ -60,15 +88,22 @@

{% endmacro %}


{% macro everything(relation) %}
{{ return( adapter.dispatch('everything', 'dbtplyr') (relation) ) }}
{% endmacro %}

{% macro default__everything(relation) %}

{%set cols = dbtplyr.get_column_names(relation) %}
{{return(cols)}}

{% 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 = [] %}
Expand Down
8 changes: 8 additions & 0 deletions macros/where_helpers.sql
Original file line number Diff line number Diff line change
@@ -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) ~ ")" }}
Expand All @@ -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) ~ ")" }}
Expand Down

0 comments on commit bf3573f

Please sign in to comment.