Skip to content

Commit 2652976

Browse files
committed
Print messages when no physical layer or model evals occurred
1 parent e0f922f commit 2652976

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

sqlmesh/core/console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ def show_model_difference_summary(
13031303
):
13041304
self._print(
13051305
Tree(
1306-
f"[bold]Differences from the `{context_diff.create_from if context_diff.is_new_environment else context_diff.environment}` environment:\n"
1306+
f"\n[bold]Differences from the `{context_diff.create_from if context_diff.is_new_environment else context_diff.environment}` environment:\n"
13071307
)
13081308
)
13091309

sqlmesh/core/plan/evaluator.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
SnapshotInfoLike,
3838
SnapshotTableInfo,
3939
)
40+
from sqlmesh.core.scheduler import CompletionStatus
4041
from sqlmesh.core.state_sync import StateSync
4142
from sqlmesh.core.state_sync.base import PromotionResult
4243
from sqlmesh.core.user import User
@@ -136,7 +137,7 @@ def evaluate(
136137
self._push(plan, snapshots, deployability_index_for_creation)
137138
update_intervals_for_new_snapshots(plan.new_snapshots, self.state_sync)
138139
self._restate(plan, snapshots_by_name)
139-
self._backfill(
140+
first_bf_completion_status = self._backfill(
140141
plan,
141142
snapshots_by_name,
142143
before_promote_snapshots,
@@ -146,20 +147,22 @@ def evaluate(
146147
promotion_result = self._promote(
147148
plan, snapshots, before_promote_snapshots, deployability_index_for_creation
148149
)
149-
self._backfill(
150+
second_bf_completion_status = self._backfill(
150151
plan,
151152
snapshots_by_name,
152153
after_promote_snapshots,
153154
deployability_index_for_evaluation,
154155
circuit_breaker=circuit_breaker,
155156
)
157+
if (
158+
first_bf_completion_status.is_nothing_to_do
159+
and second_bf_completion_status.is_nothing_to_do
160+
):
161+
self.console.log_status_update("[green]SKIP: No model batches to execute[/green]\n")
156162
self._update_views(
157163
plan, snapshots, promotion_result, deployability_index_for_evaluation
158164
)
159165

160-
if not plan.requires_backfill:
161-
self.console.log_success("Virtual Update executed successfully")
162-
163166
execute_environment_statements(
164167
adapter=self.snapshot_evaluator.adapter,
165168
environment_statements=plan.environment_statements or [],
@@ -187,7 +190,7 @@ def _backfill(
187190
selected_snapshots: t.Set[str],
188191
deployability_index: DeployabilityIndex,
189192
circuit_breaker: t.Optional[t.Callable[[], bool]] = None,
190-
) -> None:
193+
) -> CompletionStatus:
191194
"""Backfill missing intervals for snapshots that are part of the given plan.
192195
193196
Args:
@@ -212,10 +215,10 @@ def _backfill(
212215
)
213216
)
214217
self.state_sync.add_snapshots_intervals(intervals_to_add)
215-
return
218+
return CompletionStatus.NOTHING_TO_DO
216219

217220
if not plan.requires_backfill or not selected_snapshots:
218-
return
221+
return CompletionStatus.NOTHING_TO_DO
219222

220223
scheduler = self.create_scheduler(snapshots_by_name.values())
221224
completion_status = scheduler.run(
@@ -236,6 +239,8 @@ def _backfill(
236239
if completion_status.is_failure:
237240
raise PlanError("Plan application failed.")
238241

242+
return completion_status
243+
239244
def _push(
240245
self,
241246
plan: EvaluatablePlan,
@@ -279,6 +284,7 @@ def _should_create(s: Snapshot) -> bool:
279284
on_start=lambda x: self.console.start_creation_progress(
280285
x, plan.environment, self.default_catalog
281286
),
287+
on_no_work=self.console.log_status_update,
282288
on_complete=self.console.update_creation_progress,
283289
)
284290
completed = True

sqlmesh/core/snapshot/evaluator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ def create(
279279
snapshots: t.Dict[SnapshotId, Snapshot],
280280
deployability_index: t.Optional[DeployabilityIndex] = None,
281281
on_start: t.Optional[t.Callable] = None,
282+
on_no_work: t.Optional[t.Callable] = None,
282283
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
283284
allow_destructive_snapshots: t.Optional[t.Set[str]] = None,
284285
) -> None:
@@ -289,6 +290,7 @@ def create(
289290
snapshots: Mapping of snapshot ID to snapshot.
290291
deployability_index: Determines snapshots that are deployable in the context of this creation.
291292
on_start: A callback to initialize the snapshot creation progress bar.
293+
on_no_work: A callback to call when no snapshots are to be created.
292294
on_complete: A callback to call on each successfully created snapshot.
293295
allow_destructive_snapshots: Set of snapshots that are allowed to have destructive schema changes.
294296
"""
@@ -348,6 +350,8 @@ def _get_data_objects(schema: exp.Table, gateway: t.Optional[str] = None) -> t.S
348350
target_deployability_flags[snapshot.name].sort()
349351

350352
if not snapshots_to_create:
353+
if on_no_work:
354+
on_no_work("\n[green]SKIP: No physical layer updates to perform[/green]\n")
351355
return
352356
if on_start:
353357
on_start(len(snapshots_to_create))

tests/cli/test_cli.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ def assert_plan_success(result, new_env="prod", from_env="prod") -> None:
154154
assert_backfill_success(result)
155155

156156

157-
def assert_virtual_update(result) -> None:
158-
assert "Virtual Update executed" in result.output
159-
160-
161157
def test_version(runner, tmp_path):
162158
from sqlmesh import __version__ as SQLMESH_VERSION
163159

@@ -275,7 +271,7 @@ def test_plan_skip_backfill(runner, tmp_path, flag):
275271
input="y\n",
276272
)
277273
assert result.exit_code == 0
278-
assert_virtual_update(result)
274+
assert_virtual_layer_updated(result)
279275
assert "Model batches executed" not in result.output
280276

281277

@@ -404,8 +400,9 @@ def test_plan_dev_create_from_virtual(runner, tmp_path):
404400
)
405401
assert result.exit_code == 0
406402
assert_new_env(result, "dev2", "dev", initialize=False)
403+
assert "SKIP: No physical layer updates to perform" in result.output
404+
assert "SKIP: No model batches to execute" in result.output
407405
assert_virtual_layer_updated(result)
408-
assert_virtual_update(result)
409406

410407

411408
def test_plan_dev_create_from(runner, tmp_path):
@@ -542,7 +539,6 @@ def test_plan_dev_no_changes(runner, tmp_path):
542539
assert result.exit_code == 0
543540
assert_new_env(result, "dev", initialize=False)
544541
assert_virtual_layer_updated(result)
545-
assert_virtual_update(result)
546542

547543

548544
def test_plan_nonbreaking(runner, tmp_path):

0 commit comments

Comments
 (0)