Skip to content

Commit 98decf5

Browse files
authored
Fix: Support run flag in the plan command (#4043)
1 parent ca1116c commit 98decf5

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

sqlmesh/core/context.py

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

1391-
max_interval_end_per_model = self._get_max_interval_end_per_model(
1392-
snapshots, backfill_models
1393-
)
1394-
# If no end date is specified, use the max interval end from prod
1395-
# to prevent unintended evaluation of the entire DAG.
1396-
default_start, default_end = self._get_plan_default_start_end(
1397-
snapshots, max_interval_end_per_model, backfill_models, modified_model_names
1398-
)
1391+
max_interval_end_per_model = None
1392+
default_start, default_end = None, None
1393+
if not run:
1394+
max_interval_end_per_model = self._get_max_interval_end_per_model(
1395+
snapshots, backfill_models
1396+
)
1397+
# If no end date is specified, use the max interval end from prod
1398+
# to prevent unintended evaluation of the entire DAG.
1399+
default_start, default_end = self._get_plan_default_start_end(
1400+
snapshots, max_interval_end_per_model, backfill_models, modified_model_names
1401+
)
13991402

1400-
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.
1401-
self.state_sync.refresh_snapshot_intervals(context_diff.snapshots.values())
1403+
# Refresh snapshot intervals to ensure that they are up to date with values reflected in the max_interval_end_per_model.
1404+
self.state_sync.refresh_snapshot_intervals(context_diff.snapshots.values())
14021405

14031406
return self.PLAN_BUILDER_TYPE(
14041407
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)