Skip to content

Commit b0e0eed

Browse files
committed
Only include snapshots with virtual layer views in promotion progress bar
1 parent 177d98f commit b0e0eed

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

248248
@abc.abstractmethod
249-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
249+
def update_promotion_progress(
250+
self,
251+
snapshot: SnapshotInfoLike,
252+
promoted: bool,
253+
snapshots_with_virtual_views: t.List[SnapshotId],
254+
) -> None:
250255
"""Update the snapshot promotion progress."""
251256

252257
@abc.abstractmethod
@@ -474,7 +479,12 @@ def start_promotion_progress(
474479
) -> None:
475480
pass
476481

477-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
482+
def update_promotion_progress(
483+
self,
484+
snapshot: SnapshotInfoLike,
485+
promoted: bool,
486+
snapshots_with_virtual_views: t.List[SnapshotId],
487+
) -> None:
478488
pass
479489

480490
def stop_promotion_progress(self, success: bool = True) -> None:
@@ -950,12 +960,28 @@ def start_promotion_progress(
950960
self.environment_naming_info = environment_naming_info
951961
self.default_catalog = default_catalog
952962

953-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
963+
def update_promotion_progress(
964+
self,
965+
snapshot: SnapshotInfoLike,
966+
promoted: bool,
967+
snapshots_with_virtual_views: t.List[SnapshotId],
968+
) -> None:
954969
"""Update the snapshot promotion progress."""
955-
if self.promotion_progress is not None and self.promotion_task is not None:
970+
if (
971+
self.promotion_progress is not None
972+
and self.promotion_task is not None
973+
and snapshot.snapshot_id in snapshots_with_virtual_views
974+
):
956975
if self.verbosity >= Verbosity.VERBOSE:
957976
action_str = (
958-
"[green]promoted[/green]" if promoted else "[yellow]demoted[/yellow]"
977+
""
978+
if promoted:
979+
action_str = (
980+
"[yellow]updated[/yellow]"
981+
if snapshot.previous_version
982+
else "[green]created[/green]"
983+
)
984+
action_str = action_str or "[red]dropped[/red]"
959985
).ljust(len("promoted"))
960986
self.promotion_progress.live.console.print(
961987
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}"
@@ -2816,7 +2842,12 @@ def start_promotion_progress(
28162842
self.promotion_status = (0, total_tasks)
28172843
print(f"Virtually Updating '{environment_naming_info.name}'")
28182844

2819-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2845+
def update_promotion_progress(
2846+
self,
2847+
snapshot: SnapshotInfoLike,
2848+
promoted: bool,
2849+
snapshots_with_virtual_views: t.List[SnapshotId],
2850+
) -> None:
28202851
"""Update the snapshot promotion progress."""
28212852
num_promotions, total_promotions = self.promotion_status
28222853
num_promotions += 1
@@ -2947,7 +2978,12 @@ def start_promotion_progress(
29472978
) -> None:
29482979
self._write(f"Starting promotion for {total_tasks} snapshots")
29492980

2950-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2981+
def update_promotion_progress(
2982+
self,
2983+
snapshot: SnapshotInfoLike,
2984+
promoted: bool,
2985+
snapshots_with_virtual_views: t.List[SnapshotId],
2986+
) -> None:
29512987
self._write(f"Promoting {snapshot.name}")
29522988

29532989
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
@@ -375,8 +375,14 @@ def _update_views(
375375

376376
environment = plan.environment
377377

378+
# progress bar should only show snapshots that have a virtual layer view
379+
snapshots_with_virtual_views = [
380+
s.snapshot_id
381+
for s in [*promotion_result.added, *promotion_result.removed]
382+
if s.is_model and s.model_kind_name and not s.model_kind_name.is_symbolic
383+
]
378384
self.console.start_promotion_progress(
379-
len(promotion_result.added) + len(promotion_result.removed),
385+
len(snapshots_with_virtual_views),
380386
environment.naming_info,
381387
self.default_catalog,
382388
)
@@ -388,15 +394,19 @@ def _update_views(
388394
[snapshots[s.snapshot_id] for s in promotion_result.added],
389395
environment.naming_info,
390396
deployability_index=deployability_index,
391-
on_complete=lambda s: self.console.update_promotion_progress(s, True),
397+
on_complete=lambda s: self.console.update_promotion_progress(
398+
s, True, snapshots_with_virtual_views
399+
),
392400
snapshots=snapshots,
393401
)
394402
if promotion_result.removed_environment_naming_info:
395403
self._demote_snapshots(
396404
plan,
397405
promotion_result.removed,
398406
promotion_result.removed_environment_naming_info,
399-
on_complete=lambda s: self.console.update_promotion_progress(s, False),
407+
on_complete=lambda s: self.console.update_promotion_progress(
408+
s, False, snapshots_with_virtual_views
409+
),
400410
)
401411

402412
self.state_sync.finalize(environment)

sqlmesh/core/snapshot/evaluator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,8 @@ def _promote_snapshot(
973973
)
974974
adapter.execute(snapshot.model.render_on_virtual_update(**render_kwargs))
975975

976-
if on_complete is not None:
977-
on_complete(snapshot)
976+
if on_complete is not None:
977+
on_complete(snapshot)
978978

979979
def _demote_snapshot(
980980
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)