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

Add expression_is_false dbt test macro #464

Merged
merged 3 commits into from
May 21, 2024

Conversation

wrridgeway
Copy link
Member

@wrridgeway wrridgeway commented May 21, 2024

Our current expression_is_true dbt tests can lead to some weird backwards engineering trying to figure out how to invert logic given how it employs NOT before the WHERE clause it tests. Having an alternative to avoid these situations would be helpful.

@wrridgeway wrridgeway self-assigned this May 21, 2024
@wrridgeway wrridgeway linked an issue May 21, 2024 that may be closed by this pull request
@wrridgeway
Copy link
Member Author

wrridgeway commented May 21, 2024

This is ready to go, though these test names feel backwards to me. Probably not important.

@wrridgeway wrridgeway marked this pull request as ready for review May 21, 2024 18:01
@wrridgeway wrridgeway requested a review from a team as a code owner May 21, 2024 18:01
Copy link
Contributor

@jeancochrane jeancochrane left a comment

Choose a reason for hiding this comment

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

Nice! Real quick before we merge this in, could we add some simple docs for expression_is_false to the generic tests README?

Comment on lines +9 to +27
{% test expression_is_false(
model, column_name, expression, additional_select_columns=[]
) %}
{%- set select_columns_csv = format_additional_select_columns(
additional_select_columns
) -%}
{%- if column_name -%}
{%- set columns_csv = column_name -%}
{%- if select_columns_csv -%}
{%- set columns_csv = columns_csv ~ ", " ~ select_columns_csv -%}
{%- endif -%}
{%- elif select_columns_csv -%} {%- set columns_csv = select_columns_csv -%}
{%- else -%} {%- set columns_csv = "1 AS fail" -%}
{%- endif -%}

select {{ columns_csv }}
from {{ model }}
where ({{ column_name }} {{ expression }})
{% endtest %}
Copy link
Contributor

@jeancochrane jeancochrane May 21, 2024

Choose a reason for hiding this comment

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

[Thought, non-blocking] Looks like everything here is identical to expression_is_true except for the lack of a not operator on line 26. Perhaps a sign that we could factor out the shared logic into a third macro that expression_is_true and expression_is_false both depend on? Not required by any means, but something to think about!

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not opposed to that at all.

@wrridgeway wrridgeway merged commit a45a1d0 into master May 21, 2024
8 checks passed
@wrridgeway wrridgeway deleted the 463-add-expression_is_false-dbt-test-macro branch May 21, 2024 22:09
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.

Add expression_is_false dbt test macro
2 participants