Skip to content

Commit 8dd37dd

Browse files
committed
PR feedback
1 parent aa3f8fb commit 8dd37dd

4 files changed

Lines changed: 31 additions & 22 deletions

File tree

sqlmesh/core/console.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def update_promotion_progress(
179179
self,
180180
snapshot: SnapshotInfoLike,
181181
promoted: bool,
182-
snapshots_with_virtual_views: t.List[SnapshotId],
183182
) -> None:
184183
"""Update the snapshot promotion progress."""
185184

@@ -478,7 +477,6 @@ def update_promotion_progress(
478477
self,
479478
snapshot: SnapshotInfoLike,
480479
promoted: bool,
481-
snapshots_with_virtual_views: t.List[SnapshotId],
482480
) -> None:
483481
pass
484482

@@ -959,14 +957,9 @@ def update_promotion_progress(
959957
self,
960958
snapshot: SnapshotInfoLike,
961959
promoted: bool,
962-
snapshots_with_virtual_views: t.List[SnapshotId],
963960
) -> None:
964961
"""Update the snapshot promotion progress."""
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-
):
962+
if self.promotion_progress is not None and self.promotion_task is not None:
970963
if self.verbosity >= Verbosity.VERBOSE:
971964
action_str = ""
972965
if promoted:
@@ -2809,7 +2802,6 @@ def update_promotion_progress(
28092802
self,
28102803
snapshot: SnapshotInfoLike,
28112804
promoted: bool,
2812-
snapshots_with_virtual_views: t.List[SnapshotId],
28132805
) -> None:
28142806
"""Update the snapshot promotion progress."""
28152807
num_promotions, total_promotions = self.promotion_status
@@ -2945,7 +2937,6 @@ def update_promotion_progress(
29452937
self,
29462938
snapshot: SnapshotInfoLike,
29472939
promoted: bool,
2948-
snapshots_with_virtual_views: t.List[SnapshotId],
29492940
) -> None:
29502941
self._write(f"Promoting {snapshot.name}")
29512942

sqlmesh/core/plan/evaluator.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,19 +380,17 @@ def _update_views(
380380
[snapshots[s.snapshot_id] for s in promotion_result.added],
381381
environment.naming_info,
382382
deployability_index=deployability_index,
383-
on_complete=lambda s: self.console.update_promotion_progress(
384-
s, True, snapshots_with_virtual_views
385-
),
383+
on_complete=lambda s: self.console.update_promotion_progress(s, True),
386384
snapshots=snapshots,
385+
snapshots_with_virtual_views=snapshots_with_virtual_views,
387386
)
388387
if promotion_result.removed_environment_naming_info:
389388
self._demote_snapshots(
390389
plan,
391390
promotion_result.removed,
392391
promotion_result.removed_environment_naming_info,
393-
on_complete=lambda s: self.console.update_promotion_progress(
394-
s, False, snapshots_with_virtual_views
395-
),
392+
on_complete=lambda s: self.console.update_promotion_progress(s, False),
393+
snapshots_with_virtual_views=snapshots_with_virtual_views,
396394
)
397395

398396
self.state_sync.finalize(environment)
@@ -408,6 +406,7 @@ def _promote_snapshots(
408406
snapshots: t.Dict[SnapshotId, Snapshot],
409407
deployability_index: t.Optional[DeployabilityIndex] = None,
410408
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
409+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
411410
) -> None:
412411
self.snapshot_evaluator.promote(
413412
target_snapshots,
@@ -424,6 +423,7 @@ def _promote_snapshots(
424423
environment_naming_info=environment_naming_info,
425424
deployability_index=deployability_index,
426425
on_complete=on_complete,
426+
snapshots_with_virtual_views=snapshots_with_virtual_views,
427427
)
428428

429429
def _demote_snapshots(
@@ -432,9 +432,13 @@ def _demote_snapshots(
432432
target_snapshots: t.Iterable[SnapshotTableInfo],
433433
environment_naming_info: EnvironmentNamingInfo,
434434
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
435+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
435436
) -> None:
436437
self.snapshot_evaluator.demote(
437-
target_snapshots, environment_naming_info, on_complete=on_complete
438+
target_snapshots,
439+
environment_naming_info,
440+
on_complete=on_complete,
441+
snapshots_with_virtual_views=snapshots_with_virtual_views,
438442
)
439443

440444
def _restate(self, plan: EvaluatablePlan, snapshots_by_name: t.Dict[str, Snapshot]) -> None:

sqlmesh/core/snapshot/evaluator.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def promote(
216216
snapshots: t.Optional[t.Dict[SnapshotId, Snapshot]] = None,
217217
table_mapping: t.Optional[t.Dict[str, str]] = None,
218218
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
219+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
219220
) -> None:
220221
"""Promotes the given collection of snapshots in the target environment by replacing a corresponding
221222
view with a physical table associated with the given snapshot.
@@ -249,6 +250,7 @@ def promote(
249250
environment_naming_info=environment_naming_info,
250251
deployability_index=deployability_index, # type: ignore
251252
on_complete=on_complete,
253+
snapshots_with_virtual_views=snapshots_with_virtual_views,
252254
),
253255
self.ddl_concurrent_tasks,
254256
)
@@ -258,6 +260,7 @@ def demote(
258260
target_snapshots: t.Iterable[SnapshotInfoLike],
259261
environment_naming_info: EnvironmentNamingInfo,
260262
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
263+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
261264
) -> None:
262265
"""Demotes the given collection of snapshots in the target environment by removing its view.
263266
@@ -269,7 +272,9 @@ def demote(
269272
with self.concurrent_context():
270273
concurrent_apply_to_snapshots(
271274
target_snapshots,
272-
lambda s: self._demote_snapshot(s, environment_naming_info, on_complete),
275+
lambda s: self._demote_snapshot(
276+
s, environment_naming_info, on_complete, snapshots_with_virtual_views
277+
),
273278
self.ddl_concurrent_tasks,
274279
)
275280

@@ -918,6 +923,7 @@ def _promote_snapshot(
918923
execution_time: t.Optional[TimeLike] = None,
919924
snapshots: t.Optional[t.Dict[SnapshotId, Snapshot]] = None,
920925
table_mapping: t.Optional[t.Dict[str, str]] = None,
926+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
921927
) -> None:
922928
if snapshot.is_model:
923929
adapter = self.adapter
@@ -944,22 +950,31 @@ def _promote_snapshot(
944950
)
945951
adapter.execute(snapshot.model.render_on_virtual_update(**render_kwargs))
946952

947-
if on_complete is not None:
953+
if (
954+
on_complete is not None
955+
and snapshots_with_virtual_views
956+
and snapshot.snapshot_id in snapshots_with_virtual_views
957+
):
948958
on_complete(snapshot)
949959

950960
def _demote_snapshot(
951961
self,
952962
snapshot: SnapshotInfoLike,
953963
environment_naming_info: EnvironmentNamingInfo,
954964
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]],
965+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
955966
) -> None:
956967
adapter = self.adapter
957968
view_name = snapshot.qualified_view_name.for_environment(
958969
environment_naming_info, dialect=adapter.dialect
959970
)
960971
_evaluation_strategy(snapshot, adapter).demote(view_name)
961972

962-
if on_complete is not None:
973+
if (
974+
on_complete is not None
975+
and snapshots_with_virtual_views
976+
and snapshot.snapshot_id in snapshots_with_virtual_views
977+
):
963978
on_complete(snapshot)
964979

965980
def _cleanup_snapshot(

web/server/console.py

Lines changed: 1 addition & 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, SnapshotId
14+
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike
1515
from sqlmesh.core.test import ModelTest
1616
from sqlmesh.utils.date import now_timestamp
1717
from web.server import models
@@ -174,7 +174,6 @@ def update_promotion_progress(
174174
self,
175175
snapshot: SnapshotInfoLike,
176176
promoted: bool,
177-
snapshots_with_virtual_views: t.List[SnapshotId],
178177
) -> None:
179178
if self.plan_apply_stage_tracker and self.plan_apply_stage_tracker.promote:
180179
self.plan_apply_stage_tracker.promote.update(

0 commit comments

Comments
 (0)