Skip to content

Commit b3cb99d

Browse files
treyspizeigerman
authored andcommitted
Feat: fit eval progress bar column widths to content (#4149)
1 parent 5d33825 commit b3cb99d

File tree

7 files changed

+189
-124
lines changed

7 files changed

+189
-124
lines changed

sqlmesh/core/console.py

Lines changed: 152 additions & 98 deletions
Large diffs are not rendered by default.

sqlmesh/core/plan/evaluator.py

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

364364
self.console.start_promotion_progress(
365-
len(promotion_result.added) + len(promotion_result.removed),
365+
promotion_result.added + promotion_result.removed,
366366
environment.naming_info,
367367
self.default_catalog,
368368
)

sqlmesh/core/scheduler.py

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

447447
self.console.start_evaluation_progress(
448-
{snapshot: len(intervals) for snapshot, intervals in batched_intervals.items()},
448+
batched_intervals,
449449
environment_naming_info,
450450
self.default_catalog,
451451
)

sqlmesh/core/snapshot/evaluator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def _get_data_objects(schema: exp.Table, gateway: t.Optional[str] = None) -> t.S
350350
if not snapshots_to_create:
351351
return
352352
if on_start:
353-
on_start(len(snapshots_to_create))
353+
on_start(snapshots_to_create)
354354
self._create_schemas(tables_by_schema, gateway_by_schema)
355355
self._create_snapshots(
356356
snapshots_to_create=snapshots_to_create,

sqlmesh/utils/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,15 @@ class Verbosity(IntEnum):
347347
DEFAULT = 0
348348
VERBOSE = 1
349349
VERY_VERBOSE = 2
350+
351+
@property
352+
def is_default(self) -> bool:
353+
return self == Verbosity.DEFAULT
354+
355+
@property
356+
def is_verbose(self) -> bool:
357+
return self == Verbosity.VERBOSE
358+
359+
@property
360+
def is_very_verbose(self) -> bool:
361+
return self == Verbosity.VERY_VERBOSE

tests/cli/test_cli.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ def test_plan(runner, tmp_path):
186186
assert_plan_success(result)
187187
# 'Models needing backfill' section and eval progress bar should display the same inclusive intervals
188188
assert "sqlmesh_example.incremental_model: [2020-01-01 - 2022-12-31]" in result.output
189-
assert (
190-
"sqlmesh_example.incremental_model [insert 2020-01-01 -\n2022-12-31]"
191-
in result.output
192-
)
189+
assert "sqlmesh_example.incremental_model [insert 2020-01-01 - 2022-12-31]" in result.output
193190

194191

195192
def test_plan_skip_tests(runner, tmp_path):
@@ -250,7 +247,7 @@ def test_plan_restate_model(runner, tmp_path):
250247
assert result.exit_code == 0
251248
assert_duckdb_test(result)
252249
assert "No changes to plan: project files match the `prod` environment" in result.output
253-
assert "sqlmesh_example.full_model [full refresh" in result.output
250+
assert "sqlmesh_example.full_model [full refresh" in result.output
254251
assert_model_batches_executed(result)
255252
assert_virtual_layer_updated(result)
256253

@@ -301,8 +298,8 @@ def test_plan_verbose(runner, tmp_path):
301298
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--verbose"], input="y\n"
302299
)
303300
assert_plan_success(result)
304-
assert "sqlmesh_example.seed_model created" in result.output
305-
assert "sqlmesh_example.seed_model promoted" in result.output
301+
assert "sqlmesh_example.seed_model created" in result.output
302+
assert "sqlmesh_example.seed_model promoted" in result.output
306303

307304

308305
def test_plan_very_verbose(runner, tmp_path, copy_to_temp_path):
@@ -560,8 +557,8 @@ def test_plan_nonbreaking(runner, tmp_path):
560557
assert "+ 'a' AS new_col" in result.output
561558
assert "Directly Modified: sqlmesh_example.incremental_model (Non-breaking)" in result.output
562559
assert "sqlmesh_example.full_model (Indirect Non-breaking)" in result.output
563-
assert "sqlmesh_example.incremental_model [insert" in result.output
564-
assert "sqlmesh_example.full_model evaluated [full refresh" not in result.output
560+
assert "sqlmesh_example.incremental_model [insert" in result.output
561+
assert "sqlmesh_example.full_model [full refresh" not in result.output
565562
assert_backfill_success(result)
566563

567564

@@ -618,8 +615,8 @@ def test_plan_breaking(runner, tmp_path):
618615
assert result.exit_code == 0
619616
assert "+ item_id + 1 AS item_id," in result.output
620617
assert "Directly Modified: sqlmesh_example.full_model (Breaking)" in result.output
621-
assert "sqlmesh_example.full_model [full refresh" in result.output
622-
assert "sqlmesh_example.incremental_model [insert" not in result.output
618+
assert "sqlmesh_example.full_model [full refresh" in result.output
619+
assert "sqlmesh_example.incremental_model [insert" not in result.output
623620
assert_backfill_success(result)
624621

625622

@@ -657,8 +654,8 @@ def test_plan_dev_select(runner, tmp_path):
657654
assert "+ item_id + 1 AS item_id," not in result.output
658655
assert "Directly Modified: sqlmesh_example__dev.full_model (Breaking)" not in result.output
659656
# only incremental_model backfilled
660-
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
661-
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
657+
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
658+
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
662659
assert_backfill_success(result)
663660

664661

@@ -696,8 +693,8 @@ def test_plan_dev_backfill(runner, tmp_path):
696693
"Directly Modified: sqlmesh_example__dev.incremental_model (Non-breaking)" in result.output
697694
)
698695
# only incremental_model backfilled
699-
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
700-
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
696+
assert "sqlmesh_example__dev.incremental_model [insert" in result.output
697+
assert "sqlmesh_example__dev.full_model [full refresh" not in result.output
701698
assert_backfill_success(result)
702699

703700

web/server/console.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import json
55
import typing as t
66
import unittest
7-
87
from fastapi.encoders import jsonable_encoder
98
from sse_starlette.sse import ServerSentEvent
10-
from sqlmesh.core.snapshot.definition import Interval
9+
from sqlmesh.core.snapshot.definition import Interval, Intervals
1110
from sqlmesh.core.console import TerminalConsole
1211
from sqlmesh.core.environment import EnvironmentNamingInfo
1312
from sqlmesh.core.plan.definition import EvaluatablePlan
14-
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike
13+
from sqlmesh.core.snapshot import Snapshot, SnapshotInfoLike, SnapshotTableInfo
1514
from sqlmesh.core.test import ModelTest
1615
from sqlmesh.utils.date import now_timestamp
1716
from web.server import models
@@ -41,14 +40,14 @@ def stop_plan_evaluation(self) -> None:
4140

4241
def start_creation_progress(
4342
self,
44-
total_tasks: int,
43+
snapshots: t.List[Snapshot],
4544
environment_naming_info: EnvironmentNamingInfo,
4645
default_catalog: t.Optional[str],
4746
) -> None:
4847
if self.plan_apply_stage_tracker:
4948
self.plan_apply_stage_tracker.add_stage(
5049
models.PlanStage.creation,
51-
models.PlanStageCreation(total_tasks=total_tasks, num_tasks=0),
50+
models.PlanStageCreation(total_tasks=len(snapshots), num_tasks=0),
5251
)
5352

5453
self.log_event_plan_apply()
@@ -91,11 +90,14 @@ def stop_restate_progress(self, success: bool) -> None:
9190

9291
def start_evaluation_progress(
9392
self,
94-
batch_sizes: t.Dict[Snapshot, int],
93+
batched_intervals: t.Dict[Snapshot, Intervals],
9594
environment_naming_info: EnvironmentNamingInfo,
9695
default_catalog: t.Optional[str],
9796
) -> None:
9897
if self.plan_apply_stage_tracker:
98+
batch_sizes = {
99+
snapshot: len(intervals) for snapshot, intervals in batched_intervals.items()
100+
}
99101
tasks = {
100102
snapshot.name: models.BackfillTask(
101103
completed=0,
@@ -154,15 +156,15 @@ def stop_evaluation_progress(self, success: bool = True) -> None:
154156

155157
def start_promotion_progress(
156158
self,
157-
total_tasks: int,
159+
snapshots: t.List[SnapshotTableInfo],
158160
environment_naming_info: EnvironmentNamingInfo,
159161
default_catalog: t.Optional[str],
160162
) -> None:
161163
if self.plan_apply_stage_tracker:
162164
self.plan_apply_stage_tracker.add_stage(
163165
models.PlanStage.promote,
164166
models.PlanStagePromote(
165-
total_tasks=total_tasks,
167+
total_tasks=len(snapshots),
166168
num_tasks=0,
167169
target_environment=environment_naming_info.name,
168170
),

0 commit comments

Comments
 (0)