Skip to content

Commit 7ceecfb

Browse files
committed
PR feedback
1 parent e942cba commit 7ceecfb

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

@@ -1004,14 +1002,9 @@ def update_promotion_progress(
10041002
self,
10051003
snapshot: SnapshotInfoLike,
10061004
promoted: bool,
1007-
snapshots_with_virtual_views: t.List[SnapshotId],
10081005
) -> None:
10091006
"""Update the snapshot promotion progress."""
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-
):
1007+
if self.promotion_progress is not None and self.promotion_task is not None:
10151008
if self.verbosity >= Verbosity.VERBOSE:
10161009
display_name = snapshot.display_name(
10171010
self.environment_naming_info,
@@ -2892,7 +2885,6 @@ def update_promotion_progress(
28922885
self,
28932886
snapshot: SnapshotInfoLike,
28942887
promoted: bool,
2895-
snapshots_with_virtual_views: t.List[SnapshotId],
28962888
) -> None:
28972889
"""Update the snapshot promotion progress."""
28982890
num_promotions, total_promotions = self.promotion_status
@@ -3030,7 +3022,6 @@ def update_promotion_progress(
30303022
self,
30313023
snapshot: SnapshotInfoLike,
30323024
promoted: bool,
3033-
snapshots_with_virtual_views: t.List[SnapshotId],
30343025
) -> None:
30353026
self._write(f"Promoting {snapshot.name}")
30363027

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
@@ -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, SnapshotId, SnapshotTableInfo
13+
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike, SnapshotTableInfo
1414
from sqlmesh.core.test import ModelTest
1515
from sqlmesh.utils.date import now_timestamp
1616
from web.server import models
@@ -176,7 +176,6 @@ def update_promotion_progress(
176176
self,
177177
snapshot: SnapshotInfoLike,
178178
promoted: bool,
179-
snapshots_with_virtual_views: t.List[SnapshotId],
180179
) -> None:
181180
if self.plan_apply_stage_tracker and self.plan_apply_stage_tracker.promote:
182181
self.plan_apply_stage_tracker.promote.update(

0 commit comments

Comments
 (0)