From 926bcebbeadc60df48eaf62d9cb972a1fd16be3d Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Mon, 1 Oct 2018 10:15:35 -0600 Subject: [PATCH 1/3] remove list_relations call in materialization, add test accordingly --- .../materializations/data_insert_by_period.csv | 10 ++++++++++ .../expected_insert_by_period.sql | 8 ++++++++ .../models/materializations/schema.yml | 4 ++++ .../materializations/test_insert_by_period.sql | 16 ++++++++++++++++ .../insert_by_period_materialization.sql | 4 +--- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 integration_tests/data/materializations/data_insert_by_period.csv create mode 100644 integration_tests/models/materializations/expected_insert_by_period.sql create mode 100644 integration_tests/models/materializations/schema.yml create mode 100644 integration_tests/models/materializations/test_insert_by_period.sql diff --git a/integration_tests/data/materializations/data_insert_by_period.csv b/integration_tests/data/materializations/data_insert_by_period.csv new file mode 100644 index 00000000..2b5cccf8 --- /dev/null +++ b/integration_tests/data/materializations/data_insert_by_period.csv @@ -0,0 +1,10 @@ +id,created_at +1,2017-12-02 +2,2018-01-02 +3,2018-02-02 +4,2018-03-02 +5,2018-04-02 +6,2018-05-02 +7,2018-06-02 +8,2018-07-02 +9,2018-08-02 diff --git a/integration_tests/models/materializations/expected_insert_by_period.sql b/integration_tests/models/materializations/expected_insert_by_period.sql new file mode 100644 index 00000000..b4eab657 --- /dev/null +++ b/integration_tests/models/materializations/expected_insert_by_period.sql @@ -0,0 +1,8 @@ +{{ + config( + materialized = 'view') +}} + +select * +from {{ ref('data_insert_by_period') }} +where id in (2, 3, 4, 5, 6) diff --git a/integration_tests/models/materializations/schema.yml b/integration_tests/models/materializations/schema.yml new file mode 100644 index 00000000..f5806b8b --- /dev/null +++ b/integration_tests/models/materializations/schema.yml @@ -0,0 +1,4 @@ +test_insert_by_period: + constraints: + dbt_utils.equality: + - ref('expected_insert_by_period') diff --git a/integration_tests/models/materializations/test_insert_by_period.sql b/integration_tests/models/materializations/test_insert_by_period.sql new file mode 100644 index 00000000..12474da8 --- /dev/null +++ b/integration_tests/models/materializations/test_insert_by_period.sql @@ -0,0 +1,16 @@ +{{ + config( + materialized = 'insert_by_period', + period = 'month', + timestamp_field = 'created_at', + start_date = '2018-01-01', + stop_date = '2018-06-01') +}} + +with events as ( + select * + from {{ ref('data_insert_by_period') }} + where __PERIOD_FILTER__ +) + +select * from events diff --git a/macros/materializations/insert_by_period_materialization.sql b/macros/materializations/insert_by_period_materialization.sql index 9805b95d..ceb118b6 100644 --- a/macros/materializations/insert_by_period_materialization.sql +++ b/macros/materializations/insert_by_period_materialization.sql @@ -57,9 +57,7 @@ {%- set identifier = model['name'] -%} - {%- set existing_relations = adapter.list_relations(schema=schema) -%} - {%- set old_relation = adapter.get_relation(relations_list=existing_relations, - schema=schema, identifier=identifier) -%} + {%- set old_relation = adapter.get_relation(schema=schema, identifier=identifier) -%} {%- set target_relation = api.Relation.create(identifier=identifier, schema=schema, type='table') -%} {%- set non_destructive_mode = (flags.NON_DESTRUCTIVE == True) -%} From c633db93091c79918cce845969b0bf71da9fd4ce Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Wed, 17 Oct 2018 12:21:38 -0600 Subject: [PATCH 2/3] exclude test_insert_by_period on postgres --- integration_tests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration_tests/Makefile b/integration_tests/Makefile index 243f960f..55411c2c 100644 --- a/integration_tests/Makefile +++ b/integration_tests/Makefile @@ -1,8 +1,8 @@ test-postgres: dbt seed --target postgres - dbt run --target postgres - dbt test --target postgres + dbt run --target postgres --exclude test_insert_by_period + dbt test --target postgres --exclude test_insert_by_period test-redshift: dbt seed --target redshift From de24e584cfd31c82dd83c6b2c4445c8807973394 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Wed, 17 Oct 2018 14:20:12 -0600 Subject: [PATCH 3/3] Have circleci skip the tests that the makefile skips --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 81c699c4..829ccb16 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -36,8 +36,8 @@ jobs: cd integration_tests dbt deps dbt seed --full-refresh - dbt run --full-refresh - dbt test + dbt run --full-refresh --exclude test_insert_by_period + dbt test --exclude test_insert_by_period - save_cache: key: deps1-{{ .Branch }}