Skip to content

Add a new schema test: relationships_where #161

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

Merged
merged 6 commits into from
Sep 24, 2019
Merged

Add a new schema test: relationships_where #161

merged 6 commits into from
Sep 24, 2019

Conversation

MartinGuindon
Copy link
Contributor

@MartinGuindon MartinGuindon commented Sep 17, 2019

Hello dbt-utils maintainers!

I'm submitting this PR to add a new schema test that has proven to be extremely useful.

Note that I'm not the original author of the macro. It was shared on Slack last May and I had preserved a copy of it in my project. I unfortunately didn't write down who was the original contributor... so my apologies to him/her.

The need for this macro came up a few times on Slack over these past few months so I thought I'd issue a PR anyway.

To this unknown person Thanks to @tconbeer who shared it originally on Slack! <3

Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

This is really slick @MartinGuindon! I left a couple of pretty minor comments here around the documentation + default kwarg values, but otherwise, this PR is in really good shape!

README.md Outdated
models:
- name: model_name
columns:
- name: from_column
Copy link
Contributor

Choose a reason for hiding this comment

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

cool test! I'd change from_column to id here, then remove the from: argument to the relationships_where test. I think that will reflect a more typical usage of a test like this.

It's really great that you included the from argument here as well -- that makes it possible to define a test that does not apply to a particular column, eg. a test on an expression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Done.

{% macro test_relationships_where(model, to, field) %}

{% set column_name = kwargs.get('column_name', kwargs.get('from')) %}
{% set from_condition = kwargs.get('from_condition', True) %}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is pretty minor, but I'd use "true" (a string) as the default value for from_condition and to_condition here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great feedback. Thanks, Drew

@drewbanin
Copy link
Contributor

hey @MartinGuindon can you pull fishtown-analytics/dbt-utils master into your branch? I think if you do that, then push your changes, it will fix these tests!

@MartinGuindon
Copy link
Contributor Author

Thanks @drewbanin. Done that, and fixed a small mistake at the same time.
Postgres tests are now successful but Redshift tests are failing:

  Env var required but not provided: 'CI_REDSHIFT_DBT_HOST'
Exited with code 2```

to: ref('data_test_relationships_where_table_1')
field: id
from_condition: id <> '4'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test is failing on BigQuery because the id column is being loaded as an integer. Can you change '4' to 4 here? I think we should be good to go after that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Bad habit from Snowflake where 4 = '4'...
Fixed!

Copy link
Contributor

@drewbanin drewbanin left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @MartinGuindon! This is ready to roll.

I'm going to merge this and cut a new dbt-utils release later today :)

@drewbanin drewbanin merged commit 4b1c124 into dbt-labs:master Sep 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants