1111from sqlmesh .core import constants as c
1212from sqlmesh .core .console import Console , TerminalConsole , get_console
1313from sqlmesh .core .environment import EnvironmentNamingInfo
14- from sqlmesh .core .snapshot .definition import DeployabilityIndex
14+ from sqlmesh .core .snapshot .definition import model_display_name
1515from sqlmesh .core .plan .common import (
1616 SnapshotIntervalClearRequest ,
1717 identify_restatement_intervals_across_snapshot_versions ,
2222 PlanEvaluator ,
2323)
2424from sqlmesh .core .state_sync import StateReader
25- from sqlmesh .core .snapshot .definition import (
26- SnapshotInfoMixin ,
27- )
25+ from sqlmesh .core .snapshot .definition import SnapshotInfoMixin , SnapshotNameVersionLike
2826from sqlmesh .utils import Verbosity , rich as srich , to_snake_case
2927from sqlmesh .utils .date import to_ts
3028from sqlmesh .utils .errors import SQLMeshError
@@ -81,10 +79,6 @@ class ExplainableRestatementStage(stages.RestatementStage):
8179 snapshot_intervals_to_clear : t .Dict [str , SnapshotIntervalClearRequest ]
8280 """Which snapshots from other environments would have intervals cleared as part of restatement, keyed by name"""
8381
84- deployability_index : DeployabilityIndex
85- """Deployability of those snapshots (which arent necessarily present in the current plan so we cant use the
86- plan deployability index), used for outputting physical table names"""
87-
8882 @classmethod
8983 def from_restatement_stage (
9084 cls : t .Type [ExplainableRestatementStage ],
@@ -99,29 +93,10 @@ def from_restatement_stage(
9993 loaded_snapshots = {s .snapshot_id : s for s in stage .all_snapshots .values ()},
10094 )
10195
102- snapshot_intervals_to_clear = {}
103- deployability_index = DeployabilityIndex .all_deployable ()
104-
105- if all_restatement_intervals :
106- snapshot_intervals_to_clear = {
107- s_id .name : r for s_id , r in all_restatement_intervals .items ()
108- }
109-
110- # creating a deployability index over the "snapshot intervals to clear"
111- # allows us to print the physical names of the tables affected in the console output
112- # note that we can't use the DeployabilityIndex on the plan because it only includes
113- # snapshots for the current environment, not across all environments
114- deployability_index = DeployabilityIndex .create (
115- snapshots = state_reader .get_snapshots (
116- [s .snapshot_id for s in snapshot_intervals_to_clear .values ()]
117- ),
118- start = plan .start ,
119- start_override_per_model = plan .start_override_per_model ,
120- )
121-
12296 return cls (
123- snapshot_intervals_to_clear = snapshot_intervals_to_clear ,
124- deployability_index = deployability_index ,
97+ snapshot_intervals_to_clear = {
98+ s .snapshot .name : s for s in all_restatement_intervals .values ()
99+ },
125100 all_snapshots = stage .all_snapshots ,
126101 )
127102
@@ -230,7 +205,7 @@ def visit_restatement_stage(
230205 snapshot_intervals := stage .snapshot_intervals_to_clear
231206 ):
232207 for clear_request in snapshot_intervals .values ():
233- display_name = self ._display_name (clear_request .table_info )
208+ display_name = self ._display_name (clear_request .snapshot )
234209 interval = clear_request .interval
235210 tree .add (f"{ display_name } [{ to_ts (interval [0 ])} - { to_ts (interval [1 ])} ]" )
236211
@@ -348,15 +323,22 @@ def visit_finalize_environment_stage(
348323
349324 def _display_name (
350325 self ,
351- snapshot : SnapshotInfoMixin ,
326+ snapshot : t . Union [ SnapshotInfoMixin , SnapshotNameVersionLike ] ,
352327 environment_naming_info : t .Optional [EnvironmentNamingInfo ] = None ,
353328 ) -> str :
354- return snapshot .display_name (
355- environment_naming_info or self .environment_naming_info ,
356- self .default_catalog if self .verbosity < Verbosity .VERY_VERBOSE else None ,
329+ naming_kwargs : t .Any = dict (
330+ environment_naming_info = environment_naming_info or self .environment_naming_info ,
331+ default_catalog = self .default_catalog
332+ if self .verbosity < Verbosity .VERY_VERBOSE
333+ else None ,
357334 dialect = self .dialect ,
358335 )
359336
337+ if isinstance (snapshot , SnapshotInfoMixin ):
338+ return snapshot .display_name (** naming_kwargs )
339+
340+ return model_display_name (node_name = snapshot .name , ** naming_kwargs )
341+
360342 def _limit_tree (self , tree : Tree ) -> Tree :
361343 tree_length = len (tree .children )
362344 if tree_length <= MAX_TREE_LENGTH :
0 commit comments