|
| 1 | +contract_model_schema_yml = """ |
| 2 | +version: 2 |
| 3 | +models: |
| 4 | + - name: my_model |
| 5 | + config: |
| 6 | + contract: |
| 7 | + enforced: true |
| 8 | + columns: |
| 9 | + - name: id |
| 10 | + data_type: Int32 |
| 11 | + description: hello |
| 12 | + - name: color |
| 13 | + data_type: String |
| 14 | + - name: date_day |
| 15 | + data_type: Date |
| 16 | + - name: my_model_error |
| 17 | + config: |
| 18 | + contract: |
| 19 | + enforced: true |
| 20 | + columns: |
| 21 | + - name: id |
| 22 | + data_type: Int32 |
| 23 | + description: hello |
| 24 | + tests: |
| 25 | + - unique |
| 26 | + - name: color |
| 27 | + data_type: String |
| 28 | + - name: date_day |
| 29 | + data_type: Date |
| 30 | + - name: my_model_wrong_order |
| 31 | + config: |
| 32 | + contract: |
| 33 | + enforced: true |
| 34 | + columns: |
| 35 | + - name: id |
| 36 | + data_type: UInt32 |
| 37 | + description: hello |
| 38 | + tests: |
| 39 | + - unique |
| 40 | + - name: color |
| 41 | + data_type: String |
| 42 | + - name: date_day |
| 43 | + data_type: Date |
| 44 | + - name: my_model_wrong_name |
| 45 | + config: |
| 46 | + contract: |
| 47 | + enforced: true |
| 48 | + columns: |
| 49 | + - name: id |
| 50 | + data_type: Int32 |
| 51 | + description: hello |
| 52 | + - name: color |
| 53 | + data_type: String |
| 54 | + - name: date_day |
| 55 | + data_type: Date |
| 56 | +""" |
| 57 | + |
| 58 | + |
| 59 | +# model columns in a different order to schema definitions |
| 60 | +my_model_wrong_order_sql = """ |
| 61 | +{{ |
| 62 | + config( |
| 63 | + materialized = "table" |
| 64 | + ) |
| 65 | +}} |
| 66 | +
|
| 67 | +select |
| 68 | + 'blue' as color, |
| 69 | + 1::UInt32 as id, |
| 70 | + toDate('2019-01-01') as date_day |
| 71 | +""" |
| 72 | + |
| 73 | + |
| 74 | +# model columns name different to schema definitions |
| 75 | +my_model_wrong_name_sql = """ |
| 76 | +{{ |
| 77 | + config( |
| 78 | + materialized = "table" |
| 79 | + ) |
| 80 | +}} |
| 81 | +
|
| 82 | +select |
| 83 | + 'blue' as color, |
| 84 | + 1 as error, |
| 85 | + '2019-01-01' as date_day |
| 86 | +""" |
| 87 | + |
| 88 | + |
| 89 | +my_model_data_type_sql = """ |
| 90 | +{{{{ |
| 91 | + config( |
| 92 | + materialized = "table" |
| 93 | + ) |
| 94 | +}}}} |
| 95 | +
|
| 96 | +select |
| 97 | + {sql_value} as wrong_data_type_column_name |
| 98 | +""" |
| 99 | + |
| 100 | + |
| 101 | +model_data_type_schema_yml = """ |
| 102 | +version: 2 |
| 103 | +models: |
| 104 | + - name: my_model_data_type |
| 105 | + config: |
| 106 | + contract: |
| 107 | + enforced: true |
| 108 | + columns: |
| 109 | + - name: wrong_data_type_column_name |
| 110 | + data_type: {data_type} |
| 111 | +""" |
| 112 | + |
| 113 | +my_model_view_wrong_name_sql = """ |
| 114 | +{{ |
| 115 | + config( |
| 116 | + materialized = "view" |
| 117 | + ) |
| 118 | +}} |
| 119 | +
|
| 120 | +select |
| 121 | + 'blue' as color, |
| 122 | + 1 as error, |
| 123 | + toDate('2019-01-01') as date_day |
| 124 | +""" |
| 125 | + |
| 126 | +my_model_view_wrong_order_sql = """ |
| 127 | +{{ |
| 128 | + config( |
| 129 | + materialized = "view" |
| 130 | + ) |
| 131 | +}} |
| 132 | +
|
| 133 | +select |
| 134 | + 'blue' as color, |
| 135 | + 1::UInt32 as id, |
| 136 | + toDate('2019-01-01') as date_day |
| 137 | +""" |
| 138 | + |
| 139 | + |
| 140 | +my_model_incremental_wrong_order_sql = """ |
| 141 | +{{ |
| 142 | + config( |
| 143 | + materialized = "incremental", |
| 144 | + on_schema_change='append_new_columns' |
| 145 | + ) |
| 146 | +}} |
| 147 | +
|
| 148 | +select |
| 149 | + 'blue' as color, |
| 150 | + 1::UInt32 as id, |
| 151 | + toDate('2019-01-01') as date_day |
| 152 | +""" |
| 153 | + |
| 154 | +my_model_incremental_wrong_name_sql = """ |
| 155 | +{{ |
| 156 | + config( |
| 157 | + materialized = "incremental", |
| 158 | + on_schema_change='append_new_columns' |
| 159 | + ) |
| 160 | +}} |
| 161 | +
|
| 162 | +select |
| 163 | + 'blue' as color, |
| 164 | + 1 as error, |
| 165 | + '2019-01-01' as date_day |
| 166 | +""" |
| 167 | + |
| 168 | +constraint_model_schema_yml = """ |
| 169 | +version: 2 |
| 170 | +models: |
| 171 | + - name: bad_column_constraint_model |
| 172 | + materialized: table |
| 173 | + config: |
| 174 | + contract: |
| 175 | + enforced: true |
| 176 | + columns: |
| 177 | + - name: id |
| 178 | + data_type: Int32 |
| 179 | + constraints: |
| 180 | + - type: check |
| 181 | + expression: '> 0' |
| 182 | + - name: color |
| 183 | + data_type: String |
| 184 | + - name: date_day |
| 185 | + data_type: Date |
| 186 | + - name: bad_foreign_key_model |
| 187 | + config: |
| 188 | + contract: |
| 189 | + enforced: true |
| 190 | + constraints: |
| 191 | + - type: foreign_key |
| 192 | + columns: [ id ] |
| 193 | + expression: 'foreign_key_model (id)' |
| 194 | + columns: |
| 195 | + - name: id |
| 196 | + data_type: Int32 |
| 197 | + - name: check_constraints_model |
| 198 | + config: |
| 199 | + contract: |
| 200 | + enforced: true |
| 201 | + constraints: |
| 202 | + - type: check |
| 203 | + name: valid_id |
| 204 | + expression: 'id > 100 and id < 200' |
| 205 | + columns: |
| 206 | + - name: id |
| 207 | + data_type: Int32 |
| 208 | + - name: color |
| 209 | + data_type: String |
| 210 | + - name: date_day |
| 211 | + data_type: Date |
| 212 | +""" |
| 213 | + |
| 214 | +bad_column_constraint_model_sql = """ |
| 215 | +{{ |
| 216 | + config( |
| 217 | + materialized = "table" |
| 218 | + ) |
| 219 | +}} |
| 220 | +
|
| 221 | +SELECT 5::Int32 as id, 'black' as color, toDate('2023-01-01') as date_day |
| 222 | +""" |
| 223 | + |
| 224 | +bad_foreign_key_model_sql = """ |
| 225 | +{{ |
| 226 | + config( |
| 227 | + materialized = "table" |
| 228 | + ) |
| 229 | +}} |
| 230 | +
|
| 231 | +SELECT 1::Int32 as id |
| 232 | +""" |
| 233 | + |
| 234 | +check_constraints_model_sql = """ |
| 235 | +{{ |
| 236 | + config( |
| 237 | + materialized = "table", |
| 238 | + ) |
| 239 | +}} |
| 240 | +
|
| 241 | +select |
| 242 | + 'blue' as color, |
| 243 | + 101::Int32 as id, |
| 244 | + toDate('2019-01-01') as date_day |
| 245 | +""" |
| 246 | + |
| 247 | +check_constraints_model_fail_sql = """ |
| 248 | +{{ |
| 249 | + config( |
| 250 | + materialized = "table", |
| 251 | + ) |
| 252 | +}} |
| 253 | +
|
| 254 | +select |
| 255 | + 'blue' as color, |
| 256 | + 1::Int32 as id, |
| 257 | + toDate('2019-01-01') as date_day |
| 258 | +""" |
| 259 | + |
| 260 | +custom_constraint_model_schema_yml = """ |
| 261 | +version: 2 |
| 262 | +models: |
| 263 | + - name: custom_column_constraint_model |
| 264 | + materialized: table |
| 265 | + config: |
| 266 | + contract: |
| 267 | + enforced: true |
| 268 | + columns: |
| 269 | + - name: id |
| 270 | + data_type: Int32 |
| 271 | + codec: ZSTD |
| 272 | + - name: ts |
| 273 | + data_type: timestamp |
| 274 | + - name: col_ttl |
| 275 | + data_type: String |
| 276 | + ttl: ts + INTERVAL 1 DAY |
| 277 | +""" |
| 278 | + |
| 279 | +check_custom_constraints_model_sql = """ |
| 280 | +{{ |
| 281 | + config( |
| 282 | + materialized = "table", |
| 283 | + ) |
| 284 | +}} |
| 285 | +
|
| 286 | +select |
| 287 | + 101::Int32 as id, |
| 288 | + timestamp('2025-04-16') as ts, |
| 289 | + 'blue' as col_ttl |
| 290 | +""" |
0 commit comments