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

Fix at_least_one test when group_by_columns is configured #922

Merged
merged 8 commits into from
Jul 8, 2024
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
field
a
field,value
a,1
b,
4 changes: 4 additions & 0 deletions integration_tests/models/generic_tests/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ seeds:
- name: field
data_tests:
- dbt_utils.at_least_one
- name: value
data_tests:
- dbt_utils.at_least_one:
group_by_columns: ['field']
error_if: "<1"
warn_if: "<0"

- name: data_test_expression_is_true
data_tests:
Expand Down
6 changes: 4 additions & 2 deletions macros/generic_tests/at_least_one.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ from (
select
{{ select_pruned_cols }}
from {{ model }}
where {{ column_name }} is not null
limit 1
{% if group_by_columns|length() == 0 %}
where {{ column_name }} is not null
limit 1
{% endif %}
)
select
{# In TSQL, subquery aggregate columns need aliases #}
Expand Down