Fix: Don't use SCD type 2 restatement logic in regular runs#4976
Merged
themisvaltinos merged 2 commits intomainfrom Jul 16, 2025
Merged
Fix: Don't use SCD type 2 restatement logic in regular runs#4976themisvaltinos merged 2 commits intomainfrom
themisvaltinos merged 2 commits intomainfrom
Conversation
eakmanrq
reviewed
Jul 16, 2025
sqlmesh/core/plan/evaluator.py
Outdated
| restatements_by_snapshot_id = { | ||
| stage.all_snapshots[name].snapshot_id: interval | ||
| for name, interval in plan.restatements.items() | ||
| if name in stage.all_snapshots |
Collaborator
There was a problem hiding this comment.
Why is this if needed? Is there a reason to believe a name could be in restatements but not in snapshots?
Contributor
Author
There was a problem hiding this comment.
no I was simply being cautious since I thought this stage.all_snapshots[name].snaphot_id would raise a key error in an edge case. but following the control flow when we're here it should be present
eakmanrq
reviewed
Jul 16, 2025
sqlmesh/core/scheduler.py
Outdated
| is_restatement = ( | ||
| restatements is not None | ||
| and snapshot.snapshot_id in restatements | ||
| and start >= restatements[snapshot.snapshot_id][0] |
Collaborator
There was a problem hiding this comment.
Can you explain why this start check is needed?
Contributor
Author
There was a problem hiding this comment.
I thought a partial restatement shouldn’t happen in an interval that the interval’s start is earlier than the start date of the restatement, but that’s not actually the case since the logic can handle it so i removed it
eakmanrq
approved these changes
Jul 16, 2025
izeigerman
pushed a commit
that referenced
this pull request
Aug 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This update introduces an
is_restatementflag and logic inrun_merged_intervalsto distinguish between restatements (which should clean up historical data from the restatement start date onwards) and regular runs (which should only append new changes). currently SCD Type 2 models with offset cron greater than the interval start incorrectly used restatement cleanup logic during regular scheduled runs, which can be demonstrated from the addedtest_scd_type_2_regular_run_with_offsettest.