forked from dbt-labs/dbt-audit-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_reworked_compare.yml
192 lines (171 loc) · 7.93 KB
/
unit_reworked_compare.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
unit_tests:
- name: reworked_compare_identical_tables
model: unit_reworked_compare
given:
- input: ref('unit_test_model_a')
rows:
- { "id": 1, "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": 1, "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 1, dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'identical', 'id': 2, dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'identical', 'id': 3, dbt_audit_num_rows_in_status: 3}
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id']
- name: reworked_compare_identical_tables_event_time_filter
model: unit_reworked_compare
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2', 'created_at']
reworked_compare__event_time: 'created_at'
reworked_compare__primary_key_columns: ['id']
macros:
audit_helper.get_comparison_bounds:
"min_event_time": "2024-01-02"
"max_event_time": "2024-01-03"
"event_time": 'created_at'
given:
- input: ref('unit_test_model_a')
rows:
- { "id": 1, "col1": "abc", "col2": "def", "created_at": '2024-01-01' }
- { "id": 2, "col1": "hij", "col2": "klm", "created_at": '2024-01-02' }
- { "id": 3, "col1": "nop", "col2": "qrs", "created_at": '2024-01-03' }
- input: ref('unit_test_model_b')
rows:
- { "id": 2, "col1": "hij", "col2": "klm", "created_at": '2024-01-02' }
- { "id": 3, "col1": "nop", "col2": "qrs", "created_at": '2024-01-03' }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 2, dbt_audit_num_rows_in_status: 2}
- {"dbt_audit_row_status": 'identical', 'id': 3, dbt_audit_num_rows_in_status: 2}
- name: reworked_compare_all_statuses
model: unit_reworked_compare
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id']
given:
- input: ref('unit_test_model_a')
rows:
- { "id": 1, "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": 1, "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "changed", "col2": "values" }
- { "id": 4, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 1, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'modified', 'id': 2, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'modified', 'id': 2, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'removed', 'id': 3, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'added', 'id': 4, dbt_audit_num_rows_in_status: 1}
- name: reworked_compare_identical_tables_multiple_pk_cols
model: unit_reworked_compare
overrides:
vars:
reworked_compare__columns: ['id', 'id_2', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id', 'id_2']
given:
- input: ref('unit_test_model_a')
rows:
- { "id": 12, "id_2": 3, "col1": "abc", "col2": "def" }
- { "id": 1, "id_2": 23, "col1": "hij", "col2": "klm" }
- { "id": 3, "id_2": 4, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": 12, "id_2": 3, "col1": "abc", "col2": "def" }
- { "id": 1, "id_2": 23, "col1": "hij", "col2": "klm" }
- { "id": 3, "id_2": 4, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 12, "id_2": 3, "dbt_audit_num_rows_in_status": 3}
- {"dbt_audit_row_status": 'identical', 'id': 1, "id_2": 23, "dbt_audit_num_rows_in_status": 3}
- {"dbt_audit_row_status": 'identical', 'id': 3, "id_2": 4, "dbt_audit_num_rows_in_status": 3}
- name: reworked_compare_identical_tables_single_null_pk
model: unit_reworked_compare
description: "`nonunique_pk` status checks whether a PK is unique. It's intended to avoid arbitrary comparisons, not protect against null records (that's what constraints or tests are for)."
given:
- input: ref('unit_test_model_a')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": 2, "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': , dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'identical', 'id': 2, dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'identical', 'id': 3, dbt_audit_num_rows_in_status: 3}
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id']
- name: reworked_compare_identical_tables_multiple_null_pk
model: unit_reworked_compare
given:
- input: ref('unit_test_model_a')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": , "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": , "col1": "hij", "col2": "klm" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 3, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'nonunique_pk', 'id': , dbt_audit_num_rows_in_status: 2}
- {"dbt_audit_row_status": 'nonunique_pk', 'id': , dbt_audit_num_rows_in_status: 2}
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id']
- name: reworked_compare_identical_tables_multiple_null_pk_with_duplicate_rows
description: All rows with a null ID are identical. They should both be returned as individual rows instead of being combined
model: unit_reworked_compare
given:
- input: ref('unit_test_model_a')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": , "col1": "abc", "col2": "def" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
- input: ref('unit_test_model_b')
rows:
- { "id": , "col1": "abc", "col2": "def" }
- { "id": , "col1": "abc", "col2": "def" }
- { "id": , "col1": "abc", "col2": "def" }
- { "id": 3, "col1": "nop", "col2": "qrs" }
expect:
rows:
- {"dbt_audit_row_status": 'identical', 'id': 3, dbt_audit_num_rows_in_status: 1}
- {"dbt_audit_row_status": 'nonunique_pk', 'id': , dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'nonunique_pk', 'id': , dbt_audit_num_rows_in_status: 3}
- {"dbt_audit_row_status": 'nonunique_pk', 'id': , dbt_audit_num_rows_in_status: 3}
overrides:
vars:
reworked_compare__columns: ['id', 'col1', 'col2']
reworked_compare__event_time:
reworked_compare__primary_key_columns: ['id']