|
12 | 12 | import pandas as pd # noqa: TID253 |
13 | 13 | import pytest |
14 | 14 | from pathlib import Path |
| 15 | +from sqlmesh.core.console import set_console, get_console, TerminalConsole |
15 | 16 | from sqlmesh.core.config.naming import NameInferenceConfig |
16 | 17 | from sqlmesh.utils.concurrency import NodeExecutionFailedError |
17 | 18 | import time_machine |
@@ -4330,6 +4331,49 @@ def test_indirect_non_breaking_view_is_updated_with_new_table_references( |
4330 | 4331 | assert row_num > 0 |
4331 | 4332 |
|
4332 | 4333 |
|
| 4334 | +@time_machine.travel("2023-01-08 15:00:00 UTC") |
| 4335 | +def test_plan_explain(init_and_plan_context: t.Callable): |
| 4336 | + old_console = get_console() |
| 4337 | + set_console(TerminalConsole()) |
| 4338 | + |
| 4339 | + context, plan = init_and_plan_context("examples/sushi") |
| 4340 | + context.apply(plan) |
| 4341 | + |
| 4342 | + waiter_revenue_by_day_model = context.get_model("sushi.waiter_revenue_by_day") |
| 4343 | + waiter_revenue_by_day_model = add_projection_to_model( |
| 4344 | + t.cast(SqlModel, waiter_revenue_by_day_model) |
| 4345 | + ) |
| 4346 | + context.upsert_model(waiter_revenue_by_day_model) |
| 4347 | + |
| 4348 | + waiter_revenue_by_day_snapshot = context.get_snapshot(waiter_revenue_by_day_model.name) |
| 4349 | + top_waiters_snapshot = context.get_snapshot("sushi.top_waiters") |
| 4350 | + |
| 4351 | + common_kwargs = dict(skip_tests=True, no_prompts=True, explain=True) |
| 4352 | + |
| 4353 | + # For now just making sure the plan doesn't error |
| 4354 | + context.plan("dev", **common_kwargs) |
| 4355 | + context.plan("dev", **common_kwargs, skip_backfill=True) |
| 4356 | + context.plan("dev", **common_kwargs, empty_backfill=True) |
| 4357 | + context.plan("dev", **common_kwargs, forward_only=True, enable_preview=True) |
| 4358 | + context.plan("prod", **common_kwargs) |
| 4359 | + context.plan("prod", **common_kwargs, forward_only=True) |
| 4360 | + context.plan("prod", **common_kwargs, restate_models=[waiter_revenue_by_day_model.name]) |
| 4361 | + |
| 4362 | + set_console(old_console) |
| 4363 | + |
| 4364 | + # Make sure that the now changes were actually applied |
| 4365 | + for target_env in ("dev", "prod"): |
| 4366 | + plan = context.plan_builder(target_env, skip_tests=True).build() |
| 4367 | + assert plan.has_changes |
| 4368 | + assert plan.missing_intervals |
| 4369 | + assert plan.directly_modified == {waiter_revenue_by_day_snapshot.snapshot_id} |
| 4370 | + assert len(plan.new_snapshots) == 2 |
| 4371 | + assert {s.snapshot_id for s in plan.new_snapshots} == { |
| 4372 | + waiter_revenue_by_day_snapshot.snapshot_id, |
| 4373 | + top_waiters_snapshot.snapshot_id, |
| 4374 | + } |
| 4375 | + |
| 4376 | + |
4333 | 4377 | @time_machine.travel("2023-01-08 15:00:00 UTC") |
4334 | 4378 | def test_dbt_requirements(sushi_dbt_context: Context): |
4335 | 4379 | assert set(sushi_dbt_context.requirements) == {"dbt-core", "dbt-duckdb"} |
|
0 commit comments