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 }} diff --git a/integration_tests/Makefile b/integration_tests/Makefile index ffa967cf..22e9df4b 100644 --- a/integration_tests/Makefile +++ b/integration_tests/Makefile @@ -1,8 +1,8 @@ test-postgres: dbt seed --target postgres --full-refresh - dbt run --target postgres --full-refresh - dbt test --target postgres + dbt run --target postgres --full-refresh --exclude test_insert_by_period + dbt test --target postgres --exclude test_insert_by_period test-redshift: dbt seed --target redshift --full-refresh 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) -%}