Skip to content

Commit 29d7db7

Browse files
committed
Revert "Fix: Revert "Fix: Use merge when updating auto restatements (#5016)" (#5108)"
This reverts commit 8fbf26c.
1 parent 8fbf26c commit 29d7db7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sqlmesh/core/state_sync/db/snapshot.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)