@@ -30,7 +30,7 @@ class PlanOptions(t.TypedDict):
30
30
execution_time : t .NotRequired [TimeLike ]
31
31
create_from : t .NotRequired [str ]
32
32
skip_tests : t .NotRequired [bool ]
33
- restate_models : t .NotRequired [t .Iterable [str ]]
33
+ restate_models : t .NotRequired [t .Collection [str ]]
34
34
no_gaps : t .NotRequired [bool ]
35
35
skip_backfill : t .NotRequired [bool ]
36
36
forward_only : t .NotRequired [bool ]
@@ -276,19 +276,57 @@ def run_sqlmesh_thread(
276
276
277
277
def plan_and_run (
278
278
self ,
279
+ * ,
280
+ select_models : list [str ] | None = None ,
281
+ restate_selected : bool = False ,
282
+ start : TimeLike | None = None ,
283
+ end : TimeLike | None = None ,
279
284
categorizer : t .Optional [SnapshotCategorizer ] = None ,
280
285
default_catalog : t .Optional [str ] = None ,
281
286
plan_options : t .Optional [PlanOptions ] = None ,
282
287
run_options : t .Optional [RunOptions ] = None ,
288
+ skip_run : bool = False ,
283
289
):
284
- run_options = run_options or {}
285
- plan_options = plan_options or {}
290
+ """Executes a plan and run operation
291
+
292
+ This is an opinionated interface for running a plan and run operation in
293
+ a single thread. It is recommended to use this method for most use cases.
294
+ """
295
+ run_options = run_options or RunOptions ()
296
+ plan_options = plan_options or PlanOptions ()
297
+
298
+ if plan_options .get ("select_models" ) or run_options .get ("select_models" ):
299
+ raise ValueError (
300
+ "select_models should not be set in plan_options or run_options use the `select_models` or `select_models_func` arguments instead"
301
+ )
302
+ if plan_options .get ("restate_models" ):
303
+ raise ValueError (
304
+ "restate_models should not be set in plan_options use the `restate_selected` argument with `select_models` or `select_models_func` instead"
305
+ )
306
+ select_models = select_models or []
307
+
308
+ if start :
309
+ plan_options ["start" ] = start
310
+ run_options ["start" ] = start
311
+ if end :
312
+ plan_options ["end" ] = end
313
+ run_options ["end" ] = end
314
+
315
+ if select_models :
316
+ if restate_selected :
317
+ plan_options ["restate_models" ] = select_models
318
+ plan_options ["select_models" ] = select_models
319
+ else :
320
+ plan_options ["select_models" ] = select_models
321
+ run_options ["select_models" ] = select_models
286
322
287
323
try :
288
324
self .logger .debug ("starting sqlmesh plan" )
325
+ self .logger .debug (f"selected models: { select_models } " )
289
326
yield from self .plan (categorizer , default_catalog , ** plan_options )
290
327
self .logger .debug ("starting sqlmesh run" )
291
- yield from self .run (** run_options )
328
+ if not skip_run :
329
+ yield from self .run (** run_options )
292
330
except Exception as e :
293
331
self .logger .error (f"Error during sqlmesh plan and run: { e } " )
294
332
raise e
@@ -442,15 +480,26 @@ def plan(
442
480
def plan_and_run (
443
481
self ,
444
482
environment : str ,
483
+ * ,
445
484
categorizer : t .Optional [SnapshotCategorizer ] = None ,
485
+ select_models : list [str ] | None = None ,
486
+ restate_selected : bool = False ,
487
+ start : TimeLike | None = None ,
488
+ end : TimeLike | None = None ,
446
489
default_catalog : t .Optional [str ] = None ,
447
490
plan_options : t .Optional [PlanOptions ] = None ,
448
491
run_options : t .Optional [RunOptions ] = None ,
492
+ skip_run : bool = False ,
449
493
):
450
494
with self .instance (environment , "plan_and_run" ) as mesh :
451
495
yield from mesh .plan_and_run (
496
+ start = start ,
497
+ end = end ,
498
+ select_models = select_models ,
499
+ restate_selected = restate_selected ,
452
500
categorizer = categorizer ,
453
501
default_catalog = default_catalog ,
454
502
plan_options = plan_options ,
455
503
run_options = run_options ,
504
+ skip_run = skip_run ,
456
505
)
0 commit comments