Skip to content

Commit 76b0c89

Browse files
committed
Fix: Support run flag in the plan command
1 parent f488b51 commit 76b0c89

2 files changed

Lines changed: 51 additions & 10 deletions

File tree

sqlmesh/core/context.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,17 +1376,20 @@ def plan_builder(
13761376
# This ensures that no models outside the impacted sub-DAG(s) will be backfilled unexpectedly.
13771377
backfill_models = modified_model_names or None
13781378

1379-
max_interval_end_per_model = self._get_max_interval_end_per_model(
1380-
snapshots, backfill_models
1381-
)
1382-
# If no end date is specified, use the max interval end from prod
1383-
# to prevent unintended evaluation of the entire DAG.
1384-
default_start, default_end = self._get_plan_default_start_end(
1385-
snapshots, max_interval_end_per_model, backfill_models, modified_model_names
1386-
)
1379+
max_interval_end_per_model = None
1380+
default_start, default_end = None, None
1381+
if not run:
1382+
max_interval_end_per_model = self._get_max_interval_end_per_model(
1383+
snapshots, backfill_models
1384+
)
1385+
# If no end date is specified, use the max interval end from prod
1386+
# to prevent unintended evaluation of the entire DAG.
1387+
default_start, default_end = self._get_plan_default_start_end(
1388+
snapshots, max_interval_end_per_model, backfill_models, modified_model_names
1389+
)
13871390

1388-
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.
1389-
self.state_sync.refresh_snapshot_intervals(context_diff.snapshots.values())
1391+
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.
1392+
self.state_sync.refresh_snapshot_intervals(context_diff.snapshots.values())
13901393

13911394
return self.PLAN_BUILDER_TYPE(
13921395
context_diff=context_diff,

tests/core/test_integration.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,44 @@ def test_run_with_select_models(
15121512
}
15131513

15141514

1515+
@time_machine.travel("2023-01-08 15:00:00 UTC")
1516+
def test_plan_with_run(
1517+
init_and_plan_context: t.Callable,
1518+
):
1519+
context, plan = init_and_plan_context("examples/sushi")
1520+
context.apply(plan)
1521+
1522+
model = context.get_model("sushi.waiter_revenue_by_day")
1523+
context.upsert_model(add_projection_to_model(t.cast(SqlModel, model)))
1524+
1525+
with time_machine.travel("2023-01-09 00:00:00 UTC"):
1526+
plan = context.plan(run=True)
1527+
assert plan.has_changes
1528+
assert plan.missing_intervals
1529+
1530+
context.apply(plan)
1531+
1532+
snapshots = context.state_sync.state_sync.get_snapshots(context.snapshots.values())
1533+
assert {s.name: s.intervals[0][1] for s in snapshots.values() if s.intervals} == {
1534+
'"memory"."sushi"."waiter_revenue_by_day"': to_timestamp("2023-01-09"),
1535+
'"memory"."sushi"."order_items"': to_timestamp("2023-01-09"),
1536+
'"memory"."sushi"."orders"': to_timestamp("2023-01-09"),
1537+
'"memory"."sushi"."items"': to_timestamp("2023-01-09"),
1538+
'"memory"."sushi"."customer_revenue_lifetime"': to_timestamp("2023-01-09"),
1539+
'"memory"."sushi"."customer_revenue_by_day"': to_timestamp("2023-01-09"),
1540+
'"memory"."sushi"."latest_order"': to_timestamp("2023-01-09"),
1541+
'"memory"."sushi"."waiter_names"': to_timestamp("2023-01-08"),
1542+
'"memory"."sushi"."raw_marketing"': to_timestamp("2023-01-09"),
1543+
'"memory"."sushi"."marketing"': to_timestamp("2023-01-09"),
1544+
'"memory"."sushi"."waiter_as_customer_by_day"': to_timestamp("2023-01-09"),
1545+
'"memory"."sushi"."top_waiters"': to_timestamp("2023-01-09"),
1546+
'"memory"."raw"."demographics"': to_timestamp("2023-01-09"),
1547+
"assert_item_price_above_zero": to_timestamp("2023-01-09"),
1548+
'"memory"."sushi"."active_customers"': to_timestamp("2023-01-09"),
1549+
'"memory"."sushi"."customers"': to_timestamp("2023-01-09"),
1550+
}
1551+
1552+
15151553
@time_machine.travel("2023-01-08 15:00:00 UTC")
15161554
def test_run_with_select_models_no_auto_upstream(
15171555
init_and_plan_context: t.Callable,

0 commit comments

Comments
 (0)