Skip to content

Commit 8782e9d

Browse files
committed
Only include snapshots with virtual layer views in promotion progress bar
1 parent 3e5c707 commit 8782e9d

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
@@ -172,7 +172,12 @@ def start_promotion_progress(
172172
"""Indicates that a new snapshot promotion progress has begun."""
173173

174174
@abc.abstractmethod
175-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
175+
def update_promotion_progress(
176+
self,
177+
snapshot: SnapshotInfoLike,
178+
promoted: bool,
179+
snapshots_with_virtual_views: t.List[SnapshotId],
180+
) -> None:
176181
"""Update the snapshot promotion progress."""
177182

178183
@abc.abstractmethod
@@ -406,7 +411,12 @@ def start_promotion_progress(
406411
) -> None:
407412
pass
408413

409-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
414+
def update_promotion_progress(
415+
self,
416+
snapshot: SnapshotInfoLike,
417+
promoted: bool,
418+
snapshots_with_virtual_views: t.List[SnapshotId],
419+
) -> None:
410420
pass
411421

412422
def stop_promotion_progress(self, success: bool = True) -> None:
@@ -817,12 +827,28 @@ def start_promotion_progress(
817827
self.environment_naming_info = environment_naming_info
818828
self.default_catalog = default_catalog
819829

820-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
830+
def update_promotion_progress(
831+
self,
832+
snapshot: SnapshotInfoLike,
833+
promoted: bool,
834+
snapshots_with_virtual_views: t.List[SnapshotId],
835+
) -> None:
821836
"""Update the snapshot promotion progress."""
822-
if self.promotion_progress is not None and self.promotion_task is not None:
837+
if (
838+
self.promotion_progress is not None
839+
and self.promotion_task is not None
840+
and snapshot.snapshot_id in snapshots_with_virtual_views
841+
):
823842
if self.verbosity >= Verbosity.VERBOSE:
824843
action_str = (
825-
"[green]promoted[/green]" if promoted else "[yellow]demoted[/yellow]"
844+
""
845+
if promoted:
846+
action_str = (
847+
"[yellow]updated[/yellow]"
848+
if snapshot.previous_version
849+
else "[green]created[/green]"
850+
)
851+
action_str = action_str or "[red]dropped[/red]"
826852
).ljust(len("promoted"))
827853
self.promotion_progress.live.console.print(
828854
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}"
@@ -2407,7 +2433,12 @@ def start_promotion_progress(
24072433
self.promotion_status = (0, total_tasks)
24082434
print(f"Virtually Updating '{environment_naming_info.name}'")
24092435

2410-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2436+
def update_promotion_progress(
2437+
self,
2438+
snapshot: SnapshotInfoLike,
2439+
promoted: bool,
2440+
snapshots_with_virtual_views: t.List[SnapshotId],
2441+
) -> None:
24112442
"""Update the snapshot promotion progress."""
24122443
num_promotions, total_promotions = self.promotion_status
24132444
num_promotions += 1
@@ -2538,7 +2569,12 @@ def start_promotion_progress(
25382569
) -> None:
25392570
self._write(f"Starting promotion for {total_tasks} snapshots")
25402571

2541-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2572+
def update_promotion_progress(
2573+
self,
2574+
snapshot: SnapshotInfoLike,
2575+
promoted: bool,
2576+
snapshots_with_virtual_views: t.List[SnapshotId],
2577+
) -> None:
25422578
self._write(f"Promoting {snapshot.name}")
25432579

25442580
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)