|
61 | 61 | SnapshotTableInfo, |
62 | 62 | ) |
63 | 63 | from sqlmesh.utils.date import TimeLike, now, to_date, to_datetime, to_timestamp |
64 | | -from sqlmesh.utils.errors import NoChangesPlanError |
| 64 | +from sqlmesh.utils.errors import NoChangesPlanError, SQLMeshError |
65 | 65 | from sqlmesh.utils.pydantic import validate_string |
66 | 66 | from tests.conftest import DuckDBMetadata, SushiDataValidator |
67 | 67 | from tests.utils.test_helpers import use_terminal_console |
@@ -3034,7 +3034,7 @@ def _dates_in_table(table_name: str) -> t.List[str]: |
3034 | 3034 | ] |
3035 | 3035 |
|
3036 | 3036 | # mess with A independently of SQLMesh to prove a whole day gets restated for B instead of just 1hr |
3037 | | - snapshot_table_name = ctx.table_name("test.a", False) |
| 3037 | + snapshot_table_name = ctx.table_name("test.a", "dev") |
3038 | 3038 | engine_adapter.execute( |
3039 | 3039 | f"delete from {snapshot_table_name} where cast(ts as date) == '2024-01-01'" |
3040 | 3040 | ) |
@@ -4094,6 +4094,60 @@ def test_evaluate_uncategorized_snapshot(init_and_plan_context: t.Callable): |
4094 | 4094 | assert set(df["one"].tolist()) == {1} |
4095 | 4095 |
|
4096 | 4096 |
|
| 4097 | +@time_machine.travel("2023-01-08 15:00:00 UTC") |
| 4098 | +def test_table_name(init_and_plan_context: t.Callable): |
| 4099 | + context, plan = init_and_plan_context("examples/sushi") |
| 4100 | + context.apply(plan) |
| 4101 | + |
| 4102 | + snapshot = context.get_snapshot("sushi.waiter_revenue_by_day") |
| 4103 | + assert snapshot |
| 4104 | + assert ( |
| 4105 | + context.table_name("sushi.waiter_revenue_by_day", "prod") |
| 4106 | + == f"memory.sqlmesh__sushi.sushi__waiter_revenue_by_day__{snapshot.version}" |
| 4107 | + ) |
| 4108 | + |
| 4109 | + with pytest.raises(SQLMeshError, match="Environment 'dev' was not found."): |
| 4110 | + context.table_name("sushi.waiter_revenue_by_day", "dev") |
| 4111 | + |
| 4112 | + with pytest.raises( |
| 4113 | + SQLMeshError, match="Model 'sushi.missing' was not found in environment 'prod'." |
| 4114 | + ): |
| 4115 | + context.table_name("sushi.missing", "prod") |
| 4116 | + |
| 4117 | + # Add a new projection |
| 4118 | + model = context.get_model("sushi.waiter_revenue_by_day") |
| 4119 | + context.upsert_model(add_projection_to_model(t.cast(SqlModel, model))) |
| 4120 | + |
| 4121 | + context.plan("dev_a", auto_apply=True, no_prompts=True, skip_tests=True) |
| 4122 | + |
| 4123 | + new_snapshot = context.get_snapshot("sushi.waiter_revenue_by_day") |
| 4124 | + assert new_snapshot.version != snapshot.version |
| 4125 | + |
| 4126 | + assert ( |
| 4127 | + context.table_name("sushi.waiter_revenue_by_day", "dev_a") |
| 4128 | + == f"memory.sqlmesh__sushi.sushi__waiter_revenue_by_day__{new_snapshot.version}" |
| 4129 | + ) |
| 4130 | + |
| 4131 | + # Make a forward-only change |
| 4132 | + context.upsert_model(model, stamp="forward_only") |
| 4133 | + |
| 4134 | + context.plan("dev_b", auto_apply=True, no_prompts=True, skip_tests=True, forward_only=True) |
| 4135 | + |
| 4136 | + forward_only_snapshot = context.get_snapshot("sushi.waiter_revenue_by_day") |
| 4137 | + assert forward_only_snapshot.version == snapshot.version |
| 4138 | + assert forward_only_snapshot.dev_version != snapshot.version |
| 4139 | + |
| 4140 | + assert ( |
| 4141 | + context.table_name("sushi.waiter_revenue_by_day", "dev_b") |
| 4142 | + == f"memory.sqlmesh__sushi.sushi__waiter_revenue_by_day__{forward_only_snapshot.dev_version}__dev" |
| 4143 | + ) |
| 4144 | + |
| 4145 | + assert ( |
| 4146 | + context.table_name("sushi.waiter_revenue_by_day", "dev_b", prod=True) |
| 4147 | + == f"memory.sqlmesh__sushi.sushi__waiter_revenue_by_day__{snapshot.version}" |
| 4148 | + ) |
| 4149 | + |
| 4150 | + |
4097 | 4151 | @time_machine.travel("2023-01-08 15:00:00 UTC") |
4098 | 4152 | def test_dbt_requirements(sushi_dbt_context: Context): |
4099 | 4153 | assert set(sushi_dbt_context.requirements) == {"dbt-core", "dbt-duckdb"} |
|
0 commit comments