44from dataclasses import dataclass , field
55
66from sqlmesh .core .state_sync import StateReader
7- from sqlmesh .core .snapshot import Snapshot , SnapshotId , SnapshotTableInfo , SnapshotNameVersion
7+ from sqlmesh .core .snapshot import Snapshot , SnapshotId , SnapshotIdAndVersion , SnapshotNameVersion
88from sqlmesh .core .snapshot .definition import Interval
99from sqlmesh .utils .dag import DAG
1010from sqlmesh .utils .date import now_timestamp
@@ -41,7 +41,7 @@ def is_breaking_kind_change(old: Snapshot, new: Snapshot) -> bool:
4141@dataclass
4242class SnapshotIntervalClearRequest :
4343 # affected snapshot
44- table_info : SnapshotTableInfo
44+ snapshot : SnapshotIdAndVersion
4545
4646 # which interval to clear
4747 interval : Interval
@@ -53,7 +53,7 @@ class SnapshotIntervalClearRequest:
5353
5454 @property
5555 def snapshot_id (self ) -> SnapshotId :
56- return self .table_info .snapshot_id
56+ return self .snapshot .snapshot_id
5757
5858 @property
5959 def sorted_environment_names (self ) -> t .List [str ]:
@@ -122,7 +122,7 @@ def identify_restatement_intervals_across_snapshot_versions(
122122 clear_request = snapshot_intervals_to_clear .get (affected_snapshot .snapshot_id )
123123 if not clear_request :
124124 clear_request = SnapshotIntervalClearRequest (
125- table_info = affected_snapshot , interval = interval
125+ snapshot = affected_snapshot . id_and_version , interval = interval
126126 )
127127 snapshot_intervals_to_clear [affected_snapshot .snapshot_id ] = clear_request
128128
@@ -164,19 +164,13 @@ def identify_restatement_intervals_across_snapshot_versions(
164164
165165 snapshot_name_to_widest_interval [s_id .name ] = (next_start , next_end )
166166
167- # we need to fetch full Snapshot's to get access to the SnapshotTableInfo objects
168- # required by StateSync.remove_intervals()
169- # but at this point we have minimized the list by excluding the ones that are already present in prod
170- # and also excluding the ones we have already matched earlier while traversing the environment DAGs
171- remaining_snapshots = state_reader .get_snapshots (snapshot_ids = remaining_snapshot_ids )
172- for remaining_snapshot_id , remaining_snapshot in remaining_snapshots .items ():
167+ for remaining_snapshot_id in remaining_snapshot_ids :
168+ remaining_snapshot = all_matching_non_prod_snapshots [remaining_snapshot_id ]
173169 snapshot_intervals_to_clear [remaining_snapshot_id ] = SnapshotIntervalClearRequest (
174- table_info = remaining_snapshot . table_info ,
170+ snapshot = remaining_snapshot ,
175171 interval = snapshot_name_to_widest_interval [remaining_snapshot_id .name ],
176172 )
177173
178- loaded_snapshots .update (remaining_snapshots )
179-
180174 # for any affected full_history_restatement_only snapshots, we need to widen the intervals being restated to
181175 # include the whole time range for that snapshot. This requires a call to state to load the full snapshot record,
182176 # so we only do it if necessary
@@ -187,7 +181,7 @@ def identify_restatement_intervals_across_snapshot_versions(
187181 # So for now, these are not considered
188182 s_id
189183 for s_id , s in snapshot_intervals_to_clear .items ()
190- if s .table_info .full_history_restatement_only
184+ if s .snapshot . kind_name and s . snapshot . kind_name .full_history_restatement_only
191185 ]
192186 if full_history_restatement_snapshot_ids :
193187 # only load full snapshot records that we havent already loaded
0 commit comments