|
6 | 6 | import duckdb |
7 | 7 | import pandas as pd |
8 | 8 | import pytest |
| 9 | +from freezegun import freeze_time |
9 | 10 | from pytest_mock.plugin import MockerFixture |
10 | 11 | from sqlglot import exp |
11 | 12 |
|
@@ -833,6 +834,36 @@ def test_promote_snapshots_no_gaps(state_sync: EngineAdapterStateSync, make_snap |
833 | 834 | ) |
834 | 835 |
|
835 | 836 |
|
| 837 | +@freeze_time("2023-01-08 16:00:00") |
| 838 | +def test_promote_snapshots_no_gaps_lookback( |
| 839 | + state_sync: EngineAdapterStateSync, make_snapshot: t.Callable |
| 840 | +): |
| 841 | + model = SqlModel( |
| 842 | + name="a", |
| 843 | + cron="@hourly", |
| 844 | + query=parse_one("select 1, ds"), |
| 845 | + kind=IncrementalByTimeRangeKind(time_column="ds", lookback=1), |
| 846 | + start="2023-01-01", |
| 847 | + ) |
| 848 | + |
| 849 | + snapshot = make_snapshot(model, version="a") |
| 850 | + snapshot.change_category = SnapshotChangeCategory.BREAKING |
| 851 | + state_sync.push_snapshots([snapshot]) |
| 852 | + state_sync.add_interval(snapshot, "2023-01-01", "2023-01-08 15:00:00") |
| 853 | + promote_snapshots(state_sync, [snapshot], "prod", no_gaps=True) |
| 854 | + |
| 855 | + assert now_timestamp() == to_timestamp("2023-01-08 16:00:00") |
| 856 | + |
| 857 | + new_snapshot_same_version = make_snapshot(model, version="b") |
| 858 | + new_snapshot_same_version.change_category = SnapshotChangeCategory.BREAKING |
| 859 | + new_snapshot_same_version.fingerprint = snapshot.fingerprint.copy( |
| 860 | + update={"data_hash": "new_snapshot_same_version"} |
| 861 | + ) |
| 862 | + state_sync.push_snapshots([new_snapshot_same_version]) |
| 863 | + state_sync.add_interval(new_snapshot_same_version, "2023-01-01", "2023-01-08 15:00:00") |
| 864 | + promote_snapshots(state_sync, [new_snapshot_same_version], "prod", no_gaps=True) |
| 865 | + |
| 866 | + |
836 | 867 | def test_finalize(state_sync: EngineAdapterStateSync, make_snapshot: t.Callable): |
837 | 868 | snapshot_a = make_snapshot( |
838 | 869 | SqlModel( |
|
0 commit comments