|
42 | 42 | from sqlmesh.utils import rich as srich |
43 | 43 | from sqlmesh.utils import Verbosity |
44 | 44 | 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 |
46 | 46 | from sqlmesh.utils.errors import ( |
47 | 47 | PythonModelEvalError, |
48 | 48 | NodeAuditsErrors, |
@@ -3144,10 +3144,13 @@ def _format_evaluation_model_interval(snapshot: Snapshot, interval: Interval) -> |
3144 | 3144 | or snapshot.model.kind.is_managed |
3145 | 3145 | or snapshot.model.kind.is_custom |
3146 | 3146 | ): |
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')}" |
3151 | 3154 | return "" |
3152 | 3155 |
|
3153 | 3156 |
|
|
0 commit comments