Skip to content

Commit 8db5700

Browse files
authored
Fix: display inclusive intervals in eval progress bar (#4075)
1 parent 51f6a2b commit 8db5700

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

sqlmesh/core/console.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from sqlmesh.utils import rich as srich
4343
from sqlmesh.utils import Verbosity
4444
from sqlmesh.utils.concurrency import NodeExecutionFailedError
45-
from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds, to_ds, to_datetime
45+
from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds, to_ds, make_inclusive
4646
from sqlmesh.utils.errors import (
4747
PythonModelEvalError,
4848
NodeAuditsErrors,
@@ -3144,10 +3144,13 @@ def _format_evaluation_model_interval(snapshot: Snapshot, interval: Interval) ->
31443144
or snapshot.model.kind.is_managed
31453145
or snapshot.model.kind.is_custom
31463146
):
3147-
# include time if interval < 1 day
3148-
if (interval[1] - interval[0]) < datetime.timedelta(days=1).total_seconds() * 1000:
3149-
return f"insert {to_ds(interval[0])} {to_datetime(interval[0]).strftime('%H:%M:%S')}-{to_datetime(interval[1]).strftime('%H:%M:%S')}"
3150-
return f"insert {to_ds(interval[0])} - {to_ds(interval[1])}"
3147+
inclusive_interval = make_inclusive(interval[0], interval[1])
3148+
if snapshot.model.interval_unit.is_date_granularity:
3149+
return f"insert {to_ds(inclusive_interval[0])} - {to_ds(inclusive_interval[1])}"
3150+
# omit end date if interval start/end on same day
3151+
if inclusive_interval[0].date() == inclusive_interval[1].date():
3152+
return f"insert {to_ds(inclusive_interval[0])} {inclusive_interval[0].strftime('%H:%M:%S')}-{inclusive_interval[1].strftime('%H:%M:%S')}"
3153+
return f"insert {inclusive_interval[0].strftime('%Y-%m-%d %H:%M:%S')} - {inclusive_interval[1].strftime('%Y-%m-%d %H:%M:%S')}"
31513154
return ""
31523155

31533156

tests/cli/test_cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ def test_plan_no_config(runner, tmp_path):
173173
assert "Error: SQLMesh project config could not be found" in result.output
174174

175175

176+
@time_machine.travel(FREEZE_TIME)
176177
def test_plan(runner, tmp_path):
177178
create_example_project(tmp_path)
178179

@@ -183,6 +184,12 @@ def test_plan(runner, tmp_path):
183184
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan"], input="y\n"
184185
)
185186
assert_plan_success(result)
187+
# 'Models needing backfill' section and eval progress bar should display the same inclusive intervals
188+
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+
)
186193

187194

188195
def test_plan_skip_tests(runner, tmp_path):

0 commit comments

Comments
 (0)