|
28 | 28 | IncrementalByTimeRangeKind, |
29 | 29 | IncrementalUnmanagedKind, |
30 | 30 | IncrementalByPartitionKind, |
| 31 | + IncrementalByUniqueKeyKind, |
31 | 32 | PythonModel, |
32 | 33 | SqlModel, |
33 | 34 | TimeColumn, |
@@ -2708,6 +2709,39 @@ def test_audit_wap(adapter_mock, make_snapshot): |
2708 | 2709 | adapter_mock.wap_publish.assert_called_once_with(snapshot.table_name(), wap_id) |
2709 | 2710 |
|
2710 | 2711 |
|
| 2712 | +def test_audit_with_datetime_macros(adapter_mock, make_snapshot): |
| 2713 | + evaluator = SnapshotEvaluator(adapter_mock) |
| 2714 | + |
| 2715 | + model = SqlModel( |
| 2716 | + name="test_schema.test_table", |
| 2717 | + kind=IncrementalByUniqueKeyKind(unique_key="a"), |
| 2718 | + query=parse_one("SELECT a, start_ds FROM tbl"), |
| 2719 | + audits=[ |
| 2720 | + ( |
| 2721 | + "unique_combination_of_columns", |
| 2722 | + { |
| 2723 | + "columns": exp.Array(expressions=[exp.to_column("a")]), |
| 2724 | + "condition": d.MacroVar(this="start_ds").neq("2020-01-01"), |
| 2725 | + }, |
| 2726 | + ), |
| 2727 | + ], |
| 2728 | + ) |
| 2729 | + snapshot = make_snapshot(model) |
| 2730 | + snapshot.categorize_as(SnapshotChangeCategory.BREAKING) |
| 2731 | + |
| 2732 | + adapter_mock.fetchone.return_value = (0,) |
| 2733 | + evaluator.audit(snapshot, snapshots={}, start="2020-01-01") |
| 2734 | + |
| 2735 | + call_args = adapter_mock.fetchone.call_args_list |
| 2736 | + assert len(call_args) == 1 |
| 2737 | + |
| 2738 | + unique_combination_of_columns_query = call_args[0][0][0] |
| 2739 | + assert ( |
| 2740 | + unique_combination_of_columns_query.sql(dialect="duckdb") |
| 2741 | + == """SELECT COUNT(*) FROM (SELECT "a" AS "a" FROM (SELECT * FROM "test_schema"."test_table" AS "test_table") AS "_q_0" WHERE '2020-01-01' <> '2020-01-01' GROUP BY "a" HAVING COUNT(*) > 1) AS audit""" |
| 2742 | + ) |
| 2743 | + |
| 2744 | + |
2711 | 2745 | def test_audit_set_blocking_at_use_site(adapter_mock, make_snapshot): |
2712 | 2746 | evaluator = SnapshotEvaluator(adapter_mock) |
2713 | 2747 |
|
|
0 commit comments