|
21 | 21 | earliest_start_date,
|
22 | 22 | missing_intervals,
|
23 | 23 | merge_intervals,
|
| 24 | + snapshots_to_dag, |
24 | 25 | Intervals,
|
25 | 26 | )
|
26 | 27 | from sqlmesh.core.snapshot.definition import (
|
@@ -344,35 +345,26 @@ def run(
|
344 | 345 |
|
345 | 346 | return CompletionStatus.FAILURE if errors else CompletionStatus.SUCCESS
|
346 | 347 |
|
347 |
| - def batch_intervals( |
348 |
| - self, |
349 |
| - merged_intervals: SnapshotToIntervals, |
350 |
| - start: t.Optional[TimeLike] = None, |
351 |
| - end: t.Optional[TimeLike] = None, |
352 |
| - execution_time: t.Optional[TimeLike] = None, |
353 |
| - ) -> t.Dict[Snapshot, Intervals]: |
354 |
| - def expand_range_as_interval( |
355 |
| - start_ts: int, end_ts: int, interval_unit: IntervalUnit |
356 |
| - ) -> t.List[Interval]: |
357 |
| - values = expand_range(start_ts, end_ts, interval_unit) |
358 |
| - return [(values[i], values[i + 1]) for i in range(len(values) - 1)] |
359 |
| - |
360 |
| - dag = DAG[str]() |
361 |
| - |
362 |
| - for snapshot in merged_intervals: |
363 |
| - dag.add(snapshot.name, [p.name for p in snapshot.parents]) |
364 |
| - |
365 |
| - snapshot_intervals = { |
366 |
| - snapshot: [ |
367 |
| - i |
368 |
| - for interval in intervals |
369 |
| - for i in expand_range_as_interval(*interval, snapshot.node.interval_unit) |
370 |
| - ] |
| 348 | + def batch_intervals(self, merged_intervals: SnapshotToIntervals) -> t.Dict[Snapshot, Intervals]: |
| 349 | + dag = snapshots_to_dag(merged_intervals) |
| 350 | + |
| 351 | + snapshot_intervals: t.Dict[SnapshotId, t.Tuple[Snapshot, t.List[Interval]]] = { |
| 352 | + snapshot.snapshot_id: ( |
| 353 | + snapshot, |
| 354 | + [ |
| 355 | + i |
| 356 | + for interval in intervals |
| 357 | + for i in _expand_range_as_interval(*interval, snapshot.node.interval_unit) |
| 358 | + ], |
| 359 | + ) |
371 | 360 | for snapshot, intervals in merged_intervals.items()
|
372 | 361 | }
|
373 | 362 | snapshot_batches = {}
|
374 | 363 | all_unready_intervals: t.Dict[str, set[Interval]] = {}
|
375 |
| - for snapshot, intervals in snapshot_intervals.items(): |
| 364 | + for snapshot_id in dag: |
| 365 | + if snapshot_id not in snapshot_intervals: |
| 366 | + continue |
| 367 | + snapshot, intervals = snapshot_intervals[snapshot_id] |
376 | 368 | unready = set(intervals)
|
377 | 369 | intervals = snapshot.check_ready_intervals(intervals)
|
378 | 370 | unready -= set(intervals)
|
@@ -429,7 +421,7 @@ def run_merged_intervals(
|
429 | 421 | """
|
430 | 422 | execution_time = execution_time or now_timestamp()
|
431 | 423 |
|
432 |
| - batched_intervals = self.batch_intervals(merged_intervals, start, end, execution_time) |
| 424 | + batched_intervals = self.batch_intervals(merged_intervals) |
433 | 425 |
|
434 | 426 | self.console.start_evaluation_progress(
|
435 | 427 | {snapshot: len(intervals) for snapshot, intervals in batched_intervals.items()},
|
@@ -686,3 +678,10 @@ def _resolve_one_snapshot_per_version(
|
686 | 678 | snapshot_per_version[key] = snapshot
|
687 | 679 |
|
688 | 680 | return snapshot_per_version
|
| 681 | + |
| 682 | + |
| 683 | +def _expand_range_as_interval( |
| 684 | + start_ts: int, end_ts: int, interval_unit: IntervalUnit |
| 685 | +) -> t.List[Interval]: |
| 686 | + values = expand_range(start_ts, end_ts, interval_unit) |
| 687 | + return [(values[i], values[i + 1]) for i in range(len(values) - 1)] |
0 commit comments