|
40 | 40 | from sqlmesh.utils import rich as srich |
41 | 41 | from sqlmesh.utils import Verbosity |
42 | 42 | from sqlmesh.utils.concurrency import NodeExecutionFailedError |
43 | | -from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds, to_ds, to_datetime |
| 43 | +from sqlmesh.utils.date import time_like_to_str, to_date, yesterday_ds, to_ds, make_inclusive |
44 | 44 | from sqlmesh.utils.errors import ( |
45 | 45 | PythonModelEvalError, |
46 | 46 | NodeAuditsErrors, |
@@ -2745,10 +2745,13 @@ def _format_evaluation_model_interval(snapshot: Snapshot, interval: Interval) -> |
2745 | 2745 | or snapshot.model.kind.is_managed |
2746 | 2746 | or snapshot.model.kind.is_custom |
2747 | 2747 | ): |
2748 | | - # include time if interval < 1 day |
2749 | | - if (interval[1] - interval[0]) < datetime.timedelta(days=1).total_seconds() * 1000: |
2750 | | - return f"insert {to_ds(interval[0])} {to_datetime(interval[0]).strftime('%H:%M:%S')}-{to_datetime(interval[1]).strftime('%H:%M:%S')}" |
2751 | | - return f"insert {to_ds(interval[0])} - {to_ds(interval[1])}" |
| 2748 | + inclusive_interval = make_inclusive(interval[0], interval[1]) |
| 2749 | + if snapshot.model.interval_unit.is_date_granularity: |
| 2750 | + return f"insert {to_ds(inclusive_interval[0])} - {to_ds(inclusive_interval[1])}" |
| 2751 | + # omit end date if interval start/end on same day |
| 2752 | + if inclusive_interval[0].date() == inclusive_interval[1].date(): |
| 2753 | + return f"insert {to_ds(inclusive_interval[0])} {inclusive_interval[0].strftime('%H:%M:%S')}-{inclusive_interval[1].strftime('%H:%M:%S')}" |
| 2754 | + return f"insert {inclusive_interval[0].strftime('%Y-%m-%d %H:%M:%S')} - {inclusive_interval[1].strftime('%Y-%m-%d %H:%M:%S')}" |
2752 | 2755 | return "" |
2753 | 2756 |
|
2754 | 2757 |
|
|
0 commit comments