|
48 | 48 | FullKind, |
49 | 49 | IncrementalByTimeRangeKind, |
50 | 50 | IncrementalByUniqueKeyKind, |
| 51 | + IncrementalUnmanagedKind, |
51 | 52 | Model, |
52 | 53 | ModelKind, |
53 | 54 | ModelKindName, |
@@ -2485,6 +2486,54 @@ def test_restatement_plan_ignores_changes(init_and_plan_context: t.Callable): |
2485 | 2486 | context.apply(plan) |
2486 | 2487 |
|
2487 | 2488 |
|
| 2489 | +@time_machine.travel("2023-01-08 15:00:00 UTC") |
| 2490 | +def test_restatement_plan_across_environments_snapshot_with_shared_version( |
| 2491 | + init_and_plan_context: t.Callable, |
| 2492 | +): |
| 2493 | + context, _ = init_and_plan_context("examples/sushi") |
| 2494 | + |
| 2495 | + # Change kind to incremental unmanaged |
| 2496 | + model = context.get_model("sushi.waiter_revenue_by_day") |
| 2497 | + previous_kind = model.kind.copy(update={"forward_only": True}) |
| 2498 | + assert isinstance(previous_kind, IncrementalByTimeRangeKind) |
| 2499 | + |
| 2500 | + model = model.copy( |
| 2501 | + update={"kind": IncrementalUnmanagedKind(), "physical_version": "pinned_version_12345"} |
| 2502 | + ) |
| 2503 | + context.upsert_model(model) |
| 2504 | + context.plan("prod", auto_apply=True, no_prompts=True) |
| 2505 | + |
| 2506 | + # Make some change and deploy it to both dev and prod environments |
| 2507 | + model = add_projection_to_model(t.cast(SqlModel, model)) |
| 2508 | + context.upsert_model(model) |
| 2509 | + context.plan("dev_a", auto_apply=True, no_prompts=True) |
| 2510 | + context.plan("prod", auto_apply=True, no_prompts=True) |
| 2511 | + |
| 2512 | + # Change the kind back to incremental by time range and deploy to prod |
| 2513 | + model = model.copy(update={"kind": previous_kind}) |
| 2514 | + context.upsert_model(model) |
| 2515 | + context.plan("prod", auto_apply=True, no_prompts=True) |
| 2516 | + |
| 2517 | + # Restate the model and verify that the interval hasn't been expanded because of the old snapshot |
| 2518 | + # with the same version |
| 2519 | + context.plan( |
| 2520 | + restate_models=["sushi.waiter_revenue_by_day"], |
| 2521 | + start="2023-01-06", |
| 2522 | + end="2023-01-08", |
| 2523 | + auto_apply=True, |
| 2524 | + no_prompts=True, |
| 2525 | + ) |
| 2526 | + |
| 2527 | + assert ( |
| 2528 | + context.fetchdf( |
| 2529 | + "SELECT COUNT(*) AS cnt FROM sushi.waiter_revenue_by_day WHERE one IS NOT NULL AND event_date < '2023-01-06'" |
| 2530 | + )["cnt"][0] |
| 2531 | + == 0 |
| 2532 | + ) |
| 2533 | + plan = context.plan_builder("prod").build() |
| 2534 | + assert not plan.missing_intervals |
| 2535 | + |
| 2536 | + |
2488 | 2537 | def test_restatement_plan_hourly_with_downstream_daily_restates_correct_intervals(tmp_path: Path): |
2489 | 2538 | model_a = """ |
2490 | 2539 | MODEL ( |
|
0 commit comments