Skip to content

Commit b982974

Browse files
committed
PR feedback
1 parent 370a4dd commit b982974

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
@@ -250,7 +250,6 @@ def update_promotion_progress(
250250
self,
251251
snapshot: SnapshotInfoLike,
252252
promoted: bool,
253-
snapshots_with_virtual_views: t.List[SnapshotId],
254253
) -> None:
255254
"""Update the snapshot promotion progress."""
256255

@@ -483,7 +482,6 @@ def update_promotion_progress(
483482
self,
484483
snapshot: SnapshotInfoLike,
485484
promoted: bool,
486-
snapshots_with_virtual_views: t.List[SnapshotId],
487485
) -> None:
488486
pass
489487

@@ -964,14 +962,9 @@ def update_promotion_progress(
964962
self,
965963
snapshot: SnapshotInfoLike,
966964
promoted: bool,
967-
snapshots_with_virtual_views: t.List[SnapshotId],
968965
) -> None:
969966
"""Update the snapshot promotion progress."""
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-
):
967+
if self.promotion_progress is not None and self.promotion_task is not None:
975968
if self.verbosity >= Verbosity.VERBOSE:
976969
action_str = ""
977970
if promoted:
@@ -2844,7 +2837,6 @@ def update_promotion_progress(
28442837
self,
28452838
snapshot: SnapshotInfoLike,
28462839
promoted: bool,
2847-
snapshots_with_virtual_views: t.List[SnapshotId],
28482840
) -> None:
28492841
"""Update the snapshot promotion progress."""
28502842
num_promotions, total_promotions = self.promotion_status
@@ -2980,7 +2972,6 @@ def update_promotion_progress(
29802972
self,
29812973
snapshot: SnapshotInfoLike,
29822974
promoted: bool,
2983-
snapshots_with_virtual_views: t.List[SnapshotId],
29842975
) -> None:
29852976
self._write(f"Promoting {snapshot.name}")
29862977

sqlmesh/core/plan/evaluator.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,17 @@ def _update_views(
394394
[snapshots[s.snapshot_id] for s in promotion_result.added],
395395
environment.naming_info,
396396
deployability_index=deployability_index,
397-
on_complete=lambda s: self.console.update_promotion_progress(
398-
s, True, snapshots_with_virtual_views
399-
),
397+
on_complete=lambda s: self.console.update_promotion_progress(s, True),
400398
snapshots=snapshots,
399+
snapshots_with_virtual_views=snapshots_with_virtual_views,
401400
)
402401
if promotion_result.removed_environment_naming_info:
403402
self._demote_snapshots(
404403
plan,
405404
promotion_result.removed,
406405
promotion_result.removed_environment_naming_info,
407-
on_complete=lambda s: self.console.update_promotion_progress(
408-
s, False, snapshots_with_virtual_views
409-
),
406+
on_complete=lambda s: self.console.update_promotion_progress(s, False),
407+
snapshots_with_virtual_views=snapshots_with_virtual_views,
410408
)
411409

412410
self.state_sync.finalize(environment)
@@ -422,6 +420,7 @@ def _promote_snapshots(
422420
snapshots: t.Dict[SnapshotId, Snapshot],
423421
deployability_index: t.Optional[DeployabilityIndex] = None,
424422
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
423+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
425424
) -> None:
426425
self.snapshot_evaluator.promote(
427426
target_snapshots,
@@ -438,6 +437,7 @@ def _promote_snapshots(
438437
environment_naming_info=environment_naming_info,
439438
deployability_index=deployability_index,
440439
on_complete=on_complete,
440+
snapshots_with_virtual_views=snapshots_with_virtual_views,
441441
)
442442

443443
def _demote_snapshots(
@@ -446,9 +446,13 @@ def _demote_snapshots(
446446
target_snapshots: t.Iterable[SnapshotTableInfo],
447447
environment_naming_info: EnvironmentNamingInfo,
448448
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
449+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
449450
) -> None:
450451
self.snapshot_evaluator.demote(
451-
target_snapshots, environment_naming_info, on_complete=on_complete
452+
target_snapshots,
453+
environment_naming_info,
454+
on_complete=on_complete,
455+
snapshots_with_virtual_views=snapshots_with_virtual_views,
452456
)
453457

454458
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.
@@ -257,6 +258,7 @@ def promote(
257258
environment_naming_info=environment_naming_info,
258259
deployability_index=deployability_index, # type: ignore
259260
on_complete=on_complete,
261+
snapshots_with_virtual_views=snapshots_with_virtual_views,
260262
),
261263
self.ddl_concurrent_tasks,
262264
)
@@ -266,6 +268,7 @@ def demote(
266268
target_snapshots: t.Iterable[SnapshotInfoLike],
267269
environment_naming_info: EnvironmentNamingInfo,
268270
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]] = None,
271+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
269272
) -> None:
270273
"""Demotes the given collection of snapshots in the target environment by removing its view.
271274
@@ -277,7 +280,9 @@ def demote(
277280
with self.concurrent_context():
278281
concurrent_apply_to_snapshots(
279282
target_snapshots,
280-
lambda s: self._demote_snapshot(s, environment_naming_info, on_complete),
283+
lambda s: self._demote_snapshot(
284+
s, environment_naming_info, on_complete, snapshots_with_virtual_views
285+
),
281286
self.ddl_concurrent_tasks,
282287
)
283288

@@ -943,6 +948,7 @@ def _promote_snapshot(
943948
execution_time: t.Optional[TimeLike] = None,
944949
snapshots: t.Optional[t.Dict[SnapshotId, Snapshot]] = None,
945950
table_mapping: t.Optional[t.Dict[str, str]] = None,
951+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
946952
) -> None:
947953
if snapshot.is_model:
948954
adapter = (
@@ -973,14 +979,19 @@ def _promote_snapshot(
973979
)
974980
adapter.execute(snapshot.model.render_on_virtual_update(**render_kwargs))
975981

976-
if on_complete is not None:
982+
if (
983+
on_complete is not None
984+
and snapshots_with_virtual_views
985+
and snapshot.snapshot_id in snapshots_with_virtual_views
986+
):
977987
on_complete(snapshot)
978988

979989
def _demote_snapshot(
980990
self,
981991
snapshot: SnapshotInfoLike,
982992
environment_naming_info: EnvironmentNamingInfo,
983993
on_complete: t.Optional[t.Callable[[SnapshotInfoLike], None]],
994+
snapshots_with_virtual_views: t.Optional[t.List[SnapshotId]] = None,
984995
) -> None:
985996
adapter = (
986997
self.get_adapter(snapshot.model_gateway)
@@ -992,7 +1003,11 @@ def _demote_snapshot(
9921003
)
9931004
_evaluation_strategy(snapshot, adapter).demote(view_name)
9941005

995-
if on_complete is not None:
1006+
if (
1007+
on_complete is not None
1008+
and snapshots_with_virtual_views
1009+
and snapshot.snapshot_id in snapshots_with_virtual_views
1010+
):
9961011
on_complete(snapshot)
9971012

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