Skip to content

Commit bfe389e

Browse files
committed
Move filtering into console method
1 parent 4f06133 commit bfe389e

7 files changed

Lines changed: 21 additions & 34 deletions

File tree

sqlmesh/core/console.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,13 @@ def start_promotion_progress(
968968
"Updating virtual layer ", self.console, justify="left"
969969
)
970970

971+
snapshots_with_virtual_views = [
972+
s for s in snapshots if s.is_model and not s.is_symbolic
973+
]
971974
self.promotion_progress.start()
972975
self.promotion_task = self.promotion_progress.add_task(
973976
f"Virtually updating {environment_naming_info.name}...",
974-
total=len(snapshots),
977+
total=len(snapshots_with_virtual_views),
975978
)
976979

977980
# determine name column widths if we're printing names
@@ -984,15 +987,20 @@ def start_promotion_progress(
984987
dialect=self.dialect,
985988
)
986989
)
987-
for snapshot in snapshots
990+
for snapshot in snapshots_with_virtual_views
988991
)
989992

990993
self.environment_naming_info = environment_naming_info
991994
self.default_catalog = default_catalog
992995

993996
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
994997
"""Update the snapshot promotion progress."""
995-
if self.promotion_progress is not None and self.promotion_task is not None:
998+
if (
999+
self.promotion_progress is not None
1000+
and self.promotion_task is not None
1001+
and snapshot.is_model
1002+
and not snapshot.is_symbolic
1003+
):
9961004
if self.verbosity >= Verbosity.VERBOSE:
9971005
display_name = snapshot.display_name(
9981006
self.environment_naming_info,
@@ -1007,9 +1015,7 @@ def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool)
10071015
else "[green]created[/green]"
10081016
)
10091017
action_str = action_str or "[red]dropped[/red]"
1010-
self.promotion_progress.live.console.print(
1011-
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.ljust(7)}"
1012-
)
1018+
self.promotion_progress.live.console.print(f"{display_name} {action_str}")
10131019
self.promotion_progress.update(self.promotion_task, refresh=True, advance=1)
10141020

10151021
def stop_promotion_progress(self, success: bool = True) -> None:

sqlmesh/core/environment.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,11 @@ def promoted_snapshot_id_dicts(self) -> t.List[dict]:
169169

170170
@property
171171
def promoted_snapshots(self) -> t.List[SnapshotTableInfo]:
172-
def has_virtual_view(s: SnapshotTableInfo) -> bool:
173-
return (
174-
s.is_model and s.model_kind_name is not None and not s.model_kind_name.is_symbolic
175-
)
176-
177172
if self.promoted_snapshot_ids is None:
178-
return [s for s in self.snapshots if has_virtual_view(s)]
173+
return self.snapshots
179174

180175
promoted_snapshot_ids = set(self.promoted_snapshot_ids)
181-
return [
182-
s
183-
for s in self.snapshots
184-
if s.snapshot_id in promoted_snapshot_ids and has_virtual_view(s)
185-
]
176+
return [s for s in self.snapshots if s.snapshot_id in promoted_snapshot_ids]
186177

187178
@property
188179
def previous_finalized_snapshots(self) -> t.Optional[t.List[SnapshotTableInfo]]:

sqlmesh/core/plan/definition.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,7 @@ def environment(self) -> Environment:
185185

186186
snapshots_by_name = self.context_diff.snapshots_by_name
187187
snapshots = [s.table_info for s in self.snapshots.values()]
188-
189-
# only promote snapshots with virtual layer views
190-
promoted_snapshot_ids = [
191-
s.snapshot_id
192-
for s in snapshots
193-
if s.is_model and s.model_kind_name and not s.model_kind_name.is_symbolic
194-
]
188+
promoted_snapshot_ids = None
195189

196190
if self.is_dev and not self.include_unmodified:
197191
if self.selected_models_to_backfill is not None:
@@ -208,7 +202,7 @@ def environment(self) -> Environment:
208202
promotable_snapshot_ids = self.context_diff.promotable_snapshot_ids.copy()
209203

210204
promoted_snapshot_ids = [
211-
id for id in promoted_snapshot_ids if id in promotable_snapshot_ids
205+
s.snapshot_id for s in snapshots if s.snapshot_id in promotable_snapshot_ids
212206
]
213207

214208
previous_finalized_snapshots = (

sqlmesh/core/plan/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def _update_views(
376376
environment = plan.environment
377377

378378
self.console.start_promotion_progress(
379-
len(promotion_result.added) + len(promotion_result.removed),
379+
promotion_result.added + promotion_result.removed,
380380
environment.naming_info,
381381
self.default_catalog,
382382
)

sqlmesh/core/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def run_merged_intervals(
427427
batched_intervals = self.batch_intervals(merged_intervals, deployability_index)
428428

429429
self.console.start_evaluation_progress(
430-
{snapshot: len(intervals) for snapshot, intervals in batched_intervals.items()},
430+
batched_intervals,
431431
environment_naming_info,
432432
self.default_catalog,
433433
)

tests/cli/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ def test_plan_verbose(runner, tmp_path):
294294
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--verbose"], input="y\n"
295295
)
296296
assert_plan_success(result)
297-
assert "sqlmesh_example.seed_model created" in result.output
298-
assert "sqlmesh_example.full_model created" in result.output
297+
assert "sqlmesh_example.seed_model created" in result.output
298+
assert "sqlmesh_example.full_model created" in result.output
299299

300300

301301
def test_plan_very_verbose(runner, tmp_path, copy_to_temp_path):

web/server/console.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ def start_promotion_progress(
172172

173173
self.log_event_plan_apply()
174174

175-
def update_promotion_progress(
176-
self,
177-
snapshot: SnapshotInfoLike,
178-
promoted: bool,
179-
) -> None:
175+
def update_promotion_progress(self, snapshot: SnapshotInfoLike, promoted: bool) -> None:
180176
if self.plan_apply_stage_tracker and self.plan_apply_stage_tracker.promote:
181177
self.plan_apply_stage_tracker.promote.update(
182178
{"num_tasks": self.plan_apply_stage_tracker.promote.num_tasks + 1}

0 commit comments

Comments
 (0)