Skip to content

Commit

Permalink
expression is true - rename seeds, format sql and get rid of dupe col…
Browse files Browse the repository at this point in the history
…umn handler from PR comments
  • Loading branch information
jpmmcneill committed Mar 7, 2022
1 parent 68dc341 commit 24ddca9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions integration_tests/models/schema_tests/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ models:
tests:
- dbt_utils.at_least_one

- name: data_test_expression_is_true_1
- name: data_test_expression_is_true
tests:
- dbt_utils.expression_is_true:
expression: col_a + col_b = 1
Expand All @@ -31,7 +31,7 @@ models:
expression: = 0.5
condition: col_a = 0.5

- name: data_test_expression_is_true_2
- name: data_test_expression_is_true_window_functions
tests:
- dbt_utils.expression_is_true:
expression: count(*) over (partition by col_a) = 2
Expand Down
14 changes: 3 additions & 11 deletions macros/schema_tests/expression_is_true.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

{% macro default__test_expression_is_true(model, expression, column_name, condition) %}

{% if execute %}
{%- set columns = adapter.get_columns_in_relation(model) -%}
{% for col in columns %}
{{ exceptions.raise_compiler_error(
'_test_expression_passed is a protected column name for the dbt_utils.expression_is_true test.\nPlease rename the `_test_expression_passed` field in ' ~ model.name ~'.'
) if '_test_expression_passed' == col.name|lower }}
{% endfor %}
{% endif %}

with meet_condition as (
select
*,
Expand All @@ -23,11 +14,12 @@ with meet_condition as (
{%- else %}
{{ column_name }} {{ expression }}
{%- endif %}
as _test_expression_passed
as _dbt_utils_test_expression_passed
from {{ model }}
where {{ condition }}
)

select * from meet_condition where not(_test_expression_passed)
select * from meet_condition
where not(_dbt_utils_test_expression_passed)

{% endmacro %}

0 comments on commit 24ddca9

Please sign in to comment.