File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
integration_tests/models/schema_tests Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,23 @@ models:
128
128
129
129
```
130
130
131
+ The macro accepts an optional parameter ` condition ` that allows for asserting
132
+ the ` expression ` on a subset of all records.
133
+
134
+ Usage:
135
+ ``` yaml
136
+ version : 2
137
+
138
+ models :
139
+ - name : model_name
140
+ tests :
141
+ - dbt_utils.expression_is_true :
142
+ expression : " col_a + col_b = total"
143
+ condition : " created_at > '2018-12-31'"
144
+
145
+ ```
146
+
147
+
131
148
#### recency ([ source] ( macros/schema_tests/recency.sql ) )
132
149
This schema test asserts that there is data in the referenced model at least as recent as the defined interval prior to the current timestamp.
133
150
Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ models:
17
17
tests :
18
18
- dbt_utils.expression_is_true :
19
19
expression : col_a + col_b = 1
20
-
20
+ - dbt_utils.expression_is_true :
21
+ expression : col_a = 0.5
22
+ condition : col_b = 0.5
23
+
21
24
- name : test_recency
22
25
tests :
23
26
- dbt_utils.recency :
Original file line number Diff line number Diff line change 1
- {% macro test_expression_is_true(model) %}
1
+ {% macro test_expression_is_true(model, condition = ' true ' ) %}
2
2
3
3
{% set expression = kwargs .get (' expression' , kwargs .get (' arg' )) %}
4
4
5
- with validation_errors as (
5
+ with meet_condition as (
6
+
7
+ select * from {{ model }} where {{ condition }}
8
+
9
+ ),
10
+ validation_errors as (
6
11
7
12
select
8
13
*
9
- from {{model}}
14
+ from meet_condition
10
15
where not({{expression}})
11
16
12
17
)
You can’t perform that action at this time.
0 commit comments