|
20 | 20 | earliest_start_date,
|
21 | 21 | missing_intervals,
|
22 | 22 | merge_intervals,
|
| 23 | + snapshots_to_dag, |
23 | 24 | Intervals,
|
24 | 25 | )
|
25 | 26 | from sqlmesh.core.snapshot.definition import (
|
@@ -341,35 +342,26 @@ def run(
|
341 | 342 |
|
342 | 343 | return CompletionStatus.FAILURE if errors else CompletionStatus.SUCCESS
|
343 | 344 |
|
344 |
| - def batch_intervals( |
345 |
| - self, |
346 |
| - merged_intervals: SnapshotToIntervals, |
347 |
| - start: t.Optional[TimeLike] = None, |
348 |
| - end: t.Optional[TimeLike] = None, |
349 |
| - execution_time: t.Optional[TimeLike] = None, |
350 |
| - ) -> t.Dict[Snapshot, Intervals]: |
351 |
| - def expand_range_as_interval( |
352 |
| - start_ts: int, end_ts: int, interval_unit: IntervalUnit |
353 |
| - ) -> t.List[Interval]: |
354 |
| - values = expand_range(start_ts, end_ts, interval_unit) |
355 |
| - return [(values[i], values[i + 1]) for i in range(len(values) - 1)] |
356 |
| - |
357 |
| - dag = DAG[str]() |
358 |
| - |
359 |
| - for snapshot in merged_intervals: |
360 |
| - dag.add(snapshot.name, [p.name for p in snapshot.parents]) |
361 |
| - |
362 |
| - snapshot_intervals = { |
363 |
| - snapshot: [ |
364 |
| - i |
365 |
| - for interval in intervals |
366 |
| - for i in expand_range_as_interval(*interval, snapshot.node.interval_unit) |
367 |
| - ] |
| 345 | + def batch_intervals(self, merged_intervals: SnapshotToIntervals) -> t.Dict[Snapshot, Intervals]: |
| 346 | + dag = snapshots_to_dag(merged_intervals) |
| 347 | + |
| 348 | + snapshot_intervals: t.Dict[SnapshotId, t.Tuple[Snapshot, t.List[Interval]]] = { |
| 349 | + snapshot.snapshot_id: ( |
| 350 | + snapshot, |
| 351 | + [ |
| 352 | + i |
| 353 | + for interval in intervals |
| 354 | + for i in _expand_range_as_interval(*interval, snapshot.node.interval_unit) |
| 355 | + ], |
| 356 | + ) |
368 | 357 | for snapshot, intervals in merged_intervals.items()
|
369 | 358 | }
|
370 | 359 | snapshot_batches = {}
|
371 | 360 | all_unready_intervals: t.Dict[str, set[Interval]] = {}
|
372 |
| - for snapshot, intervals in snapshot_intervals.items(): |
| 361 | + for snapshot_id in dag: |
| 362 | + if snapshot_id not in snapshot_intervals: |
| 363 | + continue |
| 364 | + snapshot, intervals = snapshot_intervals[snapshot_id] |
373 | 365 | unready = set(intervals)
|
374 | 366 | intervals = snapshot.check_ready_intervals(intervals)
|
375 | 367 | unready -= set(intervals)
|
@@ -425,7 +417,7 @@ def run_merged_intervals(
|
425 | 417 | """
|
426 | 418 | execution_time = execution_time or now_timestamp()
|
427 | 419 |
|
428 |
| - batched_intervals = self.batch_intervals(merged_intervals, start, end, execution_time) |
| 420 | + batched_intervals = self.batch_intervals(merged_intervals) |
429 | 421 |
|
430 | 422 | self.console.start_evaluation_progress(
|
431 | 423 | {snapshot: len(intervals) for snapshot, intervals in batched_intervals.items()},
|
@@ -646,3 +638,10 @@ def _resolve_one_snapshot_per_version(
|
646 | 638 | snapshot_per_version[key] = snapshot
|
647 | 639 |
|
648 | 640 | return snapshot_per_version
|
| 641 | + |
| 642 | + |
| 643 | +def _expand_range_as_interval( |
| 644 | + start_ts: int, end_ts: int, interval_unit: IntervalUnit |
| 645 | +) -> t.List[Interval]: |
| 646 | + values = expand_range(start_ts, end_ts, interval_unit) |
| 647 | + return [(values[i], values[i + 1]) for i in range(len(values) - 1)] |
0 commit comments