Feat: Improve CLI and --explain output for restatements#5348
Conversation
a17877b to
650dc13
Compare
sqlmesh/core/plan/explainer.py
Outdated
| # so that we can generate physical table names for them while explaining what's going on | ||
| remaining_snapshot_ids_to_load = set(all_restatement_intervals).difference(loaded_snapshots) | ||
| loaded_snapshots.update( | ||
| state_reader.get_snapshots(snapshot_ids=remaining_snapshot_ids_to_load) |
There was a problem hiding this comment.
I honestly don't know if it's worth doing. This will slow down the explainer a lot. Furthermore, users won't even see this by default since the large list will just be collapsed. So we'll be significantly slowing down the whole explain for the sake of something very few people will even look at (if ever).
We should only do this in the super verbose mode. Alternatively, I'm ok with not having this level of detail at all.
There was a problem hiding this comment.
The main reason I did this was for consistency with the other stages, which do output the physical table names (eg, the backfill stage). Also, without the physical table names, its difficult to indicate the snapshots that aren't promoted in any environment but are still affected.
This will slow down the explainer a lot
It wont affect the explainer at all unless restatements are both present and affect a lot of non-prod snapshots that are not already present in the local cache.
I did try to come up with a lighter way of generating correct physical table names without loading full Snapshots but I quickly aborted because of the amount of properties that are needed.
Furthermore, users won't even see this by default since the large list will just be collapsed
Ah, fair, I missed the call to _limit_tree.
Personally I don't see the point in limiting explain output ever because a partial explanation that omits output for any entry over the MAX_TREE_LENGTH of 10, especially in --verbose mode, is simply not that useful for debugging.
However, to keep in line with the existing convention, i've switched this to only load snapshots / print the full table names for -vv (Verbosity.VERY_VERBOSE)
There was a problem hiding this comment.
I think the current (default) reporting is fine. I don't think reporting physical tables adds that much value
There was a problem hiding this comment.
Ok, i'll wind it back.
But I would like to point out that one of the major criticisms of SQLMesh is that it's hard to tell exactly what's going on, which we don't help if the --explain output is intentionally vague
There was a problem hiding this comment.
Just to confirm: what you showed on the screenshot above I think is the sufficient amount of detail. Further more, I think it's more useful than individual physical tables. I think having details is important, but having too much details is overwhelming and has the opposite effect.
There was a problem hiding this comment.
Understood, i've reduced the scope of this PR accordingly :)
7640ca0 to
fcb25bf
Compare
6eaa6eb to
acad2ed
Compare
317289b to
a9ad95b
Compare
a9ad95b to
e0242f9
Compare

This PR builds on #5285 to make it easier to reason about what's going on with restatements, which are a critical part of seamless dbt compatibility.
Currently, "restatements" has some nuance:
plan.restatementsis set. However,plan.restatementsgets set for dev previews, leading to confusion when SQLMesh outputs "Restating models" when no restatements were specified--restate-modelmaps to the backfill item list, leading to "why do I suddenly have 100 models to backfill when I only specified 3"-type questions--explain, we currently just say "some intervals might cleared", instead of specifically listing the affected snapshots and what environments theyre promoted inCurrent state (before this PR)
Dev previews
--restate-modelwas not specifiedActual restatement (with
--explain)erin.testthere when I just wanted to restatesqlmesh_example.full_model??After this PR
Dev previews
Actual restatement (no
--explain)Actual restatement (with
--explain)--explainoutput makes it clear that only state is affected by this plan