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] Fast check that table is not empty #269

Open
bochkarevnv opened this issue Jul 10, 2023 · 0 comments
Open

[Feature Request] Fast check that table is not empty #269

bochkarevnv opened this issue Jul 10, 2023 · 0 comments

Comments

@bochkarevnv
Copy link

Is your feature request related to a problem? Please describe.
I need to check that table have any rows, but I don't see good expectation for that.

Describe the solution you'd like
I want fast probe if table has one row. If you want to check table not empty - you don't need to count all rows in table.

Describe alternatives you've considered
You can use expect_table_row_count_to_be_between with min_value 0, but it counts all rows in table, it can be very slow.

Additional context
In my case I write test with limiting number of rows selected for count. I think you can implement something like this.

{%- test expect_table_non_empty(model, row_condition=None) -%}
{{ default__test_expect_table_non_empty(model, row_condition) }}
{% endtest %}

{%- macro default__test_expect_table_non_empty(model, row_condition) -%}
with
    limited as (
        select 1
        from {{ model }}
        {%- if row_condition %} where {{ row_condition }} {% endif %}
        limit 1
    ),
    grouped_expression as (select count(*) as expression from limited),
    validation_errors as (select * from grouped_expression where not (expression > 0))

select *
from validation_errors

{%- endmacro -%}
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