Skip to content

Commit fc409dd

Browse files
committed
Only include snapshots with virtual layer views in promotion progress bar
1 parent 1fad828 commit fc409dd

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:
@@ -990,17 +1000,33 @@ def start_promotion_progress(
9901000
self.environment_naming_info = environment_naming_info
9911001
self.default_catalog = default_catalog
9921002

993-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
1003+
def update_promotion_progress(
1004+
self,
1005+
snapshot: SnapshotInfoLike,
1006+
promoted: bool,
1007+
snapshots_with_virtual_views: t.List[SnapshotId],
1008+
) -> None:
9941009
"""Update the snapshot promotion progress."""
995-
if self.promotion_progress is not None and self.promotion_task is not None:
1010+
if (
1011+
self.promotion_progress is not None
1012+
and self.promotion_task is not None
1013+
and snapshot.snapshot_id in snapshots_with_virtual_views
1014+
):
9961015
if self.verbosity >= Verbosity.VERBOSE:
9971016
display_name = snapshot.display_name(
9981017
self.environment_naming_info,
9991018
self.default_catalog if self.verbosity < Verbosity.VERY_VERBOSE else None,
10001019
dialect=self.dialect,
10011020
).ljust(self.promotion_column_widths["name"])
10021021
action_str = (
1003-
"[green]promoted[/green]" if promoted else "[yellow]demoted[/yellow]"
1022+
""
1023+
if promoted:
1024+
action_str = (
1025+
"[yellow]updated[/yellow]"
1026+
if snapshot.previous_version
1027+
else "[green]created[/green]"
1028+
)
1029+
action_str = action_str or "[red]dropped[/red]"
10041030
).ljust(len("promoted"))
10051031
self.promotion_progress.live.console.print(f"{display_name} {action_str}")
10061032
self.promotion_progress.update(self.promotion_task, refresh=True, advance=1)
@@ -2862,7 +2888,12 @@ def start_promotion_progress(
28622888
self.promotion_status = (0, len(snapshots))
28632889
print(f"Virtually Updating '{environment_naming_info.name}'")
28642890

2865-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
2891+
def update_promotion_progress(
2892+
self,
2893+
snapshot: SnapshotInfoLike,
2894+
promoted: bool,
2895+
snapshots_with_virtual_views: t.List[SnapshotId],
2896+
) -> None:
28662897
"""Update the snapshot promotion progress."""
28672898
num_promotions, total_promotions = self.promotion_status
28682899
num_promotions += 1
@@ -2995,7 +3026,12 @@ def start_promotion_progress(
29953026
) -> None:
29963027
self._write(f"Starting promotion for {len(snapshots)} snapshots")
29973028

2998-
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
3029+
def update_promotion_progress(
3030+
self,
3031+
snapshot: SnapshotInfoLike,
3032+
promoted: bool,
3033+
snapshots_with_virtual_views: t.List[SnapshotId],
3034+
) -> None:
29993035
self._write(f"Promoting {snapshot.name}")
30003036

30013037
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-
promotion_result.added + 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
@@ -10,7 +10,7 @@
1010
from sqlmesh.core.console import TerminalConsole
1111
from sqlmesh.core.environment import EnvironmentNamingInfo
1212
from sqlmesh.core.plan.definition import EvaluatablePlan
13-
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike, SnapshotTableInfo
13+
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike, SnapshotId, SnapshotTableInfo
1414
from sqlmesh.core.test import ModelTest
1515
from sqlmesh.utils.date import now_timestamp
1616
from web.server import models
@@ -172,7 +172,12 @@ def start_promotion_progress(
172172

173173
self.log_event_plan_apply()
174174

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
if self.plan_apply_stage_tracker and self.plan_apply_stage_tracker.promote:
177182
self.plan_apply_stage_tracker.promote.update(
178183
{"num_tasks": self.plan_apply_stage_tracker.promote.num_tasks + 1}

0 commit comments

Comments
 (0)