@@ -645,26 +645,38 @@ def remove_interval(
645645 execution_time : t .Optional [TimeLike ] = None ,
646646 remove_shared_versions : bool = False ,
647647 ) -> None :
648+ intervals_to_remove : t .Sequence [
649+ t .Tuple [t .Union [SnapshotInfoLike , SnapshotIntervals ], Interval ]
650+ ] = snapshot_intervals
648651 if remove_shared_versions :
649- name_version_mapping = {
650- s .name_version : (s , interval ) for s , interval in snapshot_intervals
651- }
652- all_snapshots = self ._get_snapshots_with_same_version (
653- [s [0 ] for s in snapshot_intervals ]
654- )
655- snapshot_intervals = [
656- (snapshot , name_version_mapping [snapshot .name_version ][1 ])
652+ name_version_mapping = {s .name_version : interval for s , interval in snapshot_intervals }
653+ all_snapshots = []
654+ for where in self ._snapshot_name_version_filter (name_version_mapping , alias = None ):
655+ all_snapshots .extend (
656+ [
657+ SnapshotIntervals (
658+ name = r [0 ], identifier = r [1 ], version = r [2 ], intervals = [], dev_intervals = []
659+ )
660+ for r in self ._fetchall (
661+ exp .select ("name" , "identifier" , "version" )
662+ .from_ (self .intervals_table )
663+ .where (where )
664+ )
665+ ]
666+ )
667+ intervals_to_remove = [
668+ (snapshot , name_version_mapping [snapshot .name_version ])
657669 for snapshot in all_snapshots
658670 ]
659671
660672 if logger .isEnabledFor (logging .INFO ):
661- snapshot_ids = ", " .join (str (s .snapshot_id ) for s , _ in snapshot_intervals )
673+ snapshot_ids = ", " .join (str (s .snapshot_id ) for s , _ in intervals_to_remove )
662674 logger .info ("Removing interval for snapshots: %s" , snapshot_ids )
663675
664676 for is_dev in (True , False ):
665677 self .engine_adapter .insert_append (
666678 self .intervals_table ,
667- _intervals_to_df (snapshot_intervals , is_dev = is_dev , is_removed = True ),
679+ _intervals_to_df (intervals_to_remove , is_dev = is_dev , is_removed = True ),
668680 columns_to_types = self ._interval_columns_to_types ,
669681 )
670682
@@ -1262,7 +1274,9 @@ def _snapshot_id_filter(
12621274 )
12631275
12641276 def _snapshot_name_version_filter (
1265- self , snapshot_name_versions : t .Iterable [SnapshotNameVersionLike ], alias : str = "snapshots"
1277+ self ,
1278+ snapshot_name_versions : t .Iterable [SnapshotNameVersionLike ],
1279+ alias : t .Optional [str ] = "snapshots" ,
12661280 ) -> t .Iterator [exp .Condition ]:
12671281 name_versions = sorted ({(s .name , s .version ) for s in snapshot_name_versions })
12681282 batches = self ._snapshot_batches (name_versions )
@@ -1305,7 +1319,7 @@ def _transaction(self) -> t.Iterator[None]:
13051319
13061320
13071321def _intervals_to_df (
1308- snapshot_intervals : t .Sequence [t .Tuple [SnapshotInfoLike , Interval ]],
1322+ snapshot_intervals : t .Sequence [t .Tuple [t . Union [ SnapshotInfoLike , SnapshotIntervals ] , Interval ]],
13091323 is_dev : bool ,
13101324 is_removed : bool ,
13111325) -> pd .DataFrame :
0 commit comments