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

remove list_relations call in materialization #84

Merged
merged 4 commits into from
Oct 17, 2018
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/Makefile
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a lot smarter than what i said


test-redshift:
dbt seed --target redshift --full-refresh
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/data/materializations/data_insert_by_period.csv
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{
config(
materialized = 'view')
}}

select *
from {{ ref('data_insert_by_period') }}
where id in (2, 3, 4, 5, 6)
4 changes: 4 additions & 0 deletions integration_tests/models/materializations/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_insert_by_period:
constraints:
dbt_utils.equality:
- ref('expected_insert_by_period')
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{
Copy link
Contributor

@drewbanin drewbanin Oct 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something hacky to get these tests to pass? Let's just not configure this model for Postgres, making it use the view materialization instead

Suggested change
{{
{% if target.type != 'postgres' %}
{{
...
}}
{% endif %}

Via: https://github.com/fishtown-analytics/dbt-utils/blob/master/integration_tests/models/cross_db_utils/test_datediff.sql

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ I guess this fails during parsing? Boo. Might be worth just implementing that if/else block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the circlei script doesn't run the makefile, I just made the circle config match.

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
4 changes: 1 addition & 3 deletions macros/materializations/insert_by_period_materialization.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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) -%}
Expand Down