@@ -77,41 +77,42 @@ def _collect_output(
7777 else :
7878 cli_console .step (f"Plan output saved to: { output_path } " )
7979
80- def execute (
80+ def deploy (
8181 self ,
8282 project_identifier : FQN ,
8383 from_stage : str ,
8484 configuration : str | None = None ,
8585 variables : List [str ] | None = None ,
86- dry_run : bool = False ,
8786 alias : str | None = None ,
88- output_path : str | None = None ,
8987 skip_plan : bool = False ,
9088 ):
91- with self ._collect_output (project_identifier , output_path ) if (
92- output_path and dry_run
93- ) else nullcontext () as output_stage :
94- query = f"EXECUTE DCM PROJECT { project_identifier .sql_identifier } "
95- if dry_run :
96- query += " PLAN"
97- else :
98- query += " DEPLOY"
99- if alias :
100- query += f' AS "{ alias } "'
101- if configuration or variables :
102- query += f" USING"
103- if configuration :
104- query += f" CONFIGURATION { configuration } "
105- if variables :
106- query += StageManager .parse_execute_variables (
107- parse_key_value_variables (variables )
108- ).removeprefix (" using" )
109- stage_path = StagePath .from_stage_str (from_stage )
110- query += f" FROM { stage_path .absolute_path ()} "
89+ query = f"EXECUTE DCM PROJECT { project_identifier .sql_identifier } DEPLOY"
90+ if alias :
91+ query += f' AS "{ alias } "'
92+ query += self ._get_configuration_and_variables_query (configuration , variables )
93+ query += self ._get_from_stage_query (from_stage )
94+ if skip_plan :
95+ query += f" SKIP PLAN"
96+ return self .execute_query (query = query )
97+
98+ def plan (
99+ self ,
100+ project_identifier : FQN ,
101+ from_stage : str ,
102+ configuration : str | None = None ,
103+ variables : List [str ] | None = None ,
104+ output_path : str | None = None ,
105+ ):
106+ with self ._collect_output (
107+ project_identifier , output_path
108+ ) if output_path else nullcontext () as output_stage :
109+ query = f"EXECUTE DCM PROJECT { project_identifier .sql_identifier } PLAN"
110+ query += self ._get_configuration_and_variables_query (
111+ configuration , variables
112+ )
113+ query += self ._get_from_stage_query (from_stage )
111114 if output_stage is not None :
112115 query += f" OUTPUT_PATH { output_stage } "
113- if skip_plan :
114- query += f" SKIP PLAN"
115116 result = self .execute_query (query = query )
116117
117118 return result
@@ -147,6 +148,42 @@ def refresh(self, project_identifier: FQN):
147148 query = f"EXECUTE DCM PROJECT { project_identifier .sql_identifier } REFRESH ALL"
148149 return self .execute_query (query = query )
149150
151+ def preview (
152+ self ,
153+ project_identifier : FQN ,
154+ object_identifier : FQN ,
155+ from_stage : str ,
156+ configuration : str | None = None ,
157+ variables : List [str ] | None = None ,
158+ limit : int | None = None ,
159+ ):
160+ query = f"EXECUTE DCM PROJECT { project_identifier .sql_identifier } PREVIEW { object_identifier .sql_identifier } "
161+ query += self ._get_configuration_and_variables_query (configuration , variables )
162+ query += self ._get_from_stage_query (from_stage )
163+ if limit is not None :
164+ query += f" LIMIT { limit } "
165+ return self .execute_query (query = query )
166+
167+ @staticmethod
168+ def _get_from_stage_query (from_stage : str ) -> str :
169+ stage_path = StagePath .from_stage_str (from_stage )
170+ return f" FROM { stage_path .absolute_path ()} "
171+
172+ @staticmethod
173+ def _get_configuration_and_variables_query (
174+ configuration : str | None , variables : List [str ] | None
175+ ) -> str :
176+ query = ""
177+ if configuration or variables :
178+ query += f" USING"
179+ if configuration :
180+ query += f" CONFIGURATION { configuration } "
181+ if variables :
182+ query += StageManager .parse_execute_variables (
183+ parse_key_value_variables (variables )
184+ ).removeprefix (" using" )
185+ return query
186+
150187 @staticmethod
151188 def sync_local_files (
152189 project_identifier : FQN , source_directory : str | None = None
0 commit comments