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

WIP: first commit - added aliasing to unique and not_null #2075

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{% set column_name = kwargs.get('column_name', kwargs.get('arg')) %}

select count(*)
from {{ model }}
where {{ column_name }} is null
from {{ model }} AS aliased
Copy link
Contributor

Choose a reason for hiding this comment

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

I just thought of something really critical here - you can currently supply an expression to these tests, eg:

models:
 - name: my_model
    tests:
      - unique:
          arg: concat(field_1, field_2)

I think code like this will no longer work if we purse this approach :/

Maybe an alternative idea is to do something like:

select count(*)
from (
  select {{ column_name }} as __dbt_not_null_field from {{ model }}
) as __dbt_test_sbq
where __dbt_not_null_field is null

I think this should support existing use cases while also addressing the current issue with BigQuery table names masking column names.

where aliased.{{ column_name }} is null

{% endmacro %}

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ select count(*)
from (

select
{{ column_name }}
aliased.{{ column_name }}
Copy link
Contributor

Choose a reason for hiding this comment

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

see above


from {{ model }}
where {{ column_name }} is not null
group by {{ column_name }}
from {{ model }} AS aliased
where aliased.{{ column_name }} is not null
group by aliased.{{ column_name }}
having count(*) > 1

) validation_errors
Expand Down