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

[Feature Request] Proportion test for varchar columns #267

Open
rpremis opened this issue Jun 14, 2023 · 1 comment
Open

[Feature Request] Proportion test for varchar columns #267

rpremis opened this issue Jun 14, 2023 · 1 comment

Comments

@rpremis
Copy link

rpremis commented Jun 14, 2023

Describe the solution you'd like
I would like to have the possibility of a proportion test for varchar type columns. As of right now, the dbt-expectations does not support this kind of test. The test would look as follows:

{% test expect_column_proportion_to_be_between(
    model, 
    column_name, 
    group_by='1=1', 
    where_clause='1=1', 
    column_condition=True, 
    min_value=0, 
    max_value=1
) %}

with column_count as (

    select

        {{ group_by }},
        count(case when {{ column_condition }} then {{ column_name }} end) as numerator,
        count({{ column_name }}) as denominator,
        numerator / denominator as proportion

    from {{ model }}
    where {{ where_clause }}
    group by {{ group_by }}

),

column_comparison as (

    select

        {{ group_by }},
        proportion between {{ min_value }} and {{ max_value }} as is_within_proportion_range

    from column_count

)

select *
from column_comparison
where not is_within_proportion_range

{% endtest %}
@rpremis rpremis changed the title [Feature Request] [Feature Request] Proportion test for varchar columns Jun 14, 2023
@rpremis
Copy link
Author

rpremis commented Jun 14, 2023

If you agree, I'd be willing to put out the PR for this.

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

No branches or pull requests

1 participant