Skip to content

Commit ee829e7

Browse files
committed
Only include snapshots with virtual layer views in promotion progress bar
1 parent 718aaaa commit ee829e7

4 files changed

Lines changed: 65 additions & 14 deletions

File tree

sqlmesh/core/console.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ def start_promotion_progress(
175175
"""Indicates that a new snapshot promotion progress has begun."""
176176

177177
@abc.abstractmethod
178-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
178+
def update_promotion_progress(
179+
self,
180+
snapshot: SnapshotInfoLike,
181+
promoted: bool,
182+
snapshots_with_virtual_views: t.List[SnapshotId],
183+
) -> None:
179184
"""Update the snapshot promotion progress."""
180185

181186
@abc.abstractmethod
@@ -469,7 +474,12 @@ def start_promotion_progress(
469474
) -> None:
470475
pass
471476

472-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
477+
def update_promotion_progress(
478+
self,
479+
snapshot: SnapshotInfoLike,
480+
promoted: bool,
481+
snapshots_with_virtual_views: t.List[SnapshotId],
482+
) -> None:
473483
pass
474484

475485
def stop_promotion_progress(self, success: bool = True) -> None:
@@ -945,12 +955,28 @@ def start_promotion_progress(
945955
self.environment_naming_info = environment_naming_info
946956
self.default_catalog = default_catalog
947957

948-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
958+
def update_promotion_progress(
959+
self,
960+
snapshot: SnapshotInfoLike,
961+
promoted: bool,
962+
snapshots_with_virtual_views: t.List[SnapshotId],
963+
) -> None:
949964
"""Update the snapshot promotion progress."""
950-
if self.promotion_progress is not None and self.promotion_task is not None:
965+
if (
966+
self.promotion_progress is not None
967+
and self.promotion_task is not None
968+
and snapshot.snapshot_id in snapshots_with_virtual_views
969+
):
951970
if self.verbosity >= Verbosity.VERBOSE:
952971
action_str = (
953-
"[green]promoted[/green]" if promoted else "[yellow]demoted[/yellow]"
972+
""
973+
if promoted:
974+
action_str = (
975+
"[yellow]updated[/yellow]"
976+
if snapshot.previous_version
977+
else "[green]created[/green]"
978+
)
979+
action_str = action_str or "[red]dropped[/red]"
954980
).ljust(len("promoted"))
955981
self.promotion_progress.live.console.print(
956982
f"{snapshot.display_name(self.environment_naming_info, self.default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None, dialect=self.dialect).ljust(self.PROGRESS_BAR_COLUMN_WIDTHS['name'])} {action_str}"
@@ -2781,7 +2807,12 @@ def start_promotion_progress(
27812807
self.promotion_status = (0, total_tasks)
27822808
print(f"Virtually Updating '{environment_naming_info.name}'")
27832809

2784-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2810+
def update_promotion_progress(
2811+
self,
2812+
snapshot: SnapshotInfoLike,
2813+
promoted: bool,
2814+
snapshots_with_virtual_views: t.List[SnapshotId],
2815+
) -> None:
27852816
"""Update the snapshot promotion progress."""
27862817
num_promotions, total_promotions = self.promotion_status
27872818
num_promotions += 1
@@ -2912,7 +2943,12 @@ def start_promotion_progress(
29122943
) -> None:
29132944
self._write(f"Starting promotion for {total_tasks} snapshots")
29142945

2915-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2946+
def update_promotion_progress(
2947+
self,
2948+
snapshot: SnapshotInfoLike,
2949+
promoted: bool,
2950+
snapshots_with_virtual_views: t.List[SnapshotId],
2951+
) -> None:
29162952
self._write(f"Promoting {snapshot.name}")
29172953

29182954
def stop_promotion_progress(self, success: bool = True) -> None:

sqlmesh/core/plan/evaluator.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,14 @@ def _update_views(
361361

362362
environment = plan.environment
363363

364+
# progress bar should only show snapshots that have a virtual layer view
365+
snapshots_with_virtual_views = [
366+
s.snapshot_id
367+
for s in [*promotion_result.added, *promotion_result.removed]
368+
if s.is_model and s.model_kind_name and not s.model_kind_name.is_symbolic
369+
]
364370
self.console.start_promotion_progress(
365-
len(promotion_result.added) + len(promotion_result.removed),
371+
len(snapshots_with_virtual_views),
366372
environment.naming_info,
367373
self.default_catalog,
368374
)
@@ -374,15 +380,19 @@ def _update_views(
374380
[snapshots[s.snapshot_id] for s in promotion_result.added],
375381
environment.naming_info,
376382
deployability_index=deployability_index,
377-
on_complete=lambda s: self.console.update_promotion_progress(s, True),
383+
on_complete=lambda s: self.console.update_promotion_progress(
384+
s, True, snapshots_with_virtual_views
385+
),
378386
snapshots=snapshots,
379387
)
380388
if promotion_result.removed_environment_naming_info:
381389
self._demote_snapshots(
382390
plan,
383391
promotion_result.removed,
384392
promotion_result.removed_environment_naming_info,
385-
on_complete=lambda s: self.console.update_promotion_progress(s, False),
393+
on_complete=lambda s: self.console.update_promotion_progress(
394+
s, False, snapshots_with_virtual_views
395+
),
386396
)
387397

388398
self.state_sync.finalize(environment)

sqlmesh/core/snapshot/evaluator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,8 @@ def _promote_snapshot(
944944
)
945945
adapter.execute(snapshot.model.render_on_virtual_update(**render_kwargs))
946946

947-
if on_complete is not None:
948-
on_complete(snapshot)
947+
if on_complete is not None:
948+
on_complete(snapshot)
949949

950950
def _demote_snapshot(
951951
self,

web/server/console.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from sqlmesh.core.console import TerminalConsole
1212
from sqlmesh.core.environment import EnvironmentNamingInfo
1313
from sqlmesh.core.plan.definition import EvaluatablePlan
14-
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike
14+
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike, SnapshotId
1515
from sqlmesh.core.test import ModelTest
1616
from sqlmesh.utils.date import now_timestamp
1717
from web.server import models
@@ -170,7 +170,12 @@ def start_promotion_progress(
170170

171171
self.log_event_plan_apply()
172172

173-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
173+
def update_promotion_progress(
174+
self,
175+
snapshot: SnapshotInfoLike,
176+
promoted: bool,
177+
snapshots_with_virtual_views: t.List[SnapshotId],
178+
) -> None:
174179
if self.plan_apply_stage_tracker and self.plan_apply_stage_tracker.promote:
175180
self.plan_apply_stage_tracker.promote.update(
176181
{"num_tasks": self.plan_apply_stage_tracker.promote.num_tasks + 1}

0 commit comments

Comments
 (0)