@@ -373,25 +373,31 @@ def update_auto_restatements(
373373 Args:
374374 next_auto_restatement_ts: A dictionary of snapshot name version to the next auto restatement timestamp.
375375 """
376+ next_auto_restatement_ts_deleted = []
377+ next_auto_restatement_ts_filtered = {}
378+ for k , v in next_auto_restatement_ts .items ():
379+ if v is None :
380+ next_auto_restatement_ts_deleted .append (k )
381+ else :
382+ next_auto_restatement_ts_filtered [k ] = v
383+
376384 for where in snapshot_name_version_filter (
377385 self .engine_adapter ,
378- next_auto_restatement_ts ,
386+ next_auto_restatement_ts_deleted ,
379387 column_prefix = "snapshot" ,
380388 alias = None ,
381389 batch_size = self .SNAPSHOT_BATCH_SIZE ,
382390 ):
383391 self .engine_adapter .delete_from (self .auto_restatements_table , where = where )
384392
385- next_auto_restatement_ts_filtered = {
386- k : v for k , v in next_auto_restatement_ts .items () if v is not None
387- }
388393 if not next_auto_restatement_ts_filtered :
389394 return
390395
391- self .engine_adapter .insert_append (
396+ self .engine_adapter .merge (
392397 self .auto_restatements_table ,
393398 _auto_restatements_to_df (next_auto_restatement_ts_filtered ),
394399 columns_to_types = self ._auto_restatement_columns_to_types ,
400+ unique_key = (exp .column ("snapshot_name" ), exp .column ("snapshot_version" )),
395401 )
396402
397403 def count (self ) -> int :
0 commit comments