diff --git a/integration_tests/data/schema_tests/data_test_at_least_one.csv b/integration_tests/data/schema_tests/data_test_at_least_one.csv index 8b75a3f5..1a78cdea 100644 --- a/integration_tests/data/schema_tests/data_test_at_least_one.csv +++ b/integration_tests/data/schema_tests/data_test_at_least_one.csv @@ -1,2 +1,3 @@ -field -a +field,value +a,1 +b, diff --git a/integration_tests/models/generic_tests/schema.yml b/integration_tests/models/generic_tests/schema.yml index cecb9c3f..b12e3c7f 100644 --- a/integration_tests/models/generic_tests/schema.yml +++ b/integration_tests/models/generic_tests/schema.yml @@ -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: diff --git a/macros/generic_tests/at_least_one.sql b/macros/generic_tests/at_least_one.sql index 74cf3191..aeba2e9f 100644 --- a/macros/generic_tests/at_least_one.sql +++ b/macros/generic_tests/at_least_one.sql @@ -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 #}