@@ -3276,6 +3276,111 @@ def test_apply_auto_restatements_disable_restatement_downstream(make_snapshot):
32763276 ]
32773277
32783278
3279+ def test_auto_restatement_triggers (make_snapshot ):
3280+ model_a = SqlModel (
3281+ name = "test_model_a" ,
3282+ kind = IncrementalByTimeRangeKind (
3283+ time_column = TimeColumn (column = "ds" ),
3284+ auto_restatement_cron = "0 10 * * *" ,
3285+ auto_restatement_intervals = 24 ,
3286+ ),
3287+ start = "2020-01-01" ,
3288+ cron = "@daily" ,
3289+ query = parse_one ("SELECT 1 as ds" ),
3290+ )
3291+ snapshot_a = make_snapshot (model_a , version = "1" )
3292+ snapshot_a .add_interval ("2020-01-01" , "2020-01-05" )
3293+ snapshot_a .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3294+
3295+ model_b = SqlModel (
3296+ name = "test_model_b" ,
3297+ kind = IncrementalByTimeRangeKind (
3298+ time_column = TimeColumn (column = "ds" ),
3299+ ),
3300+ start = "2020-01-01" ,
3301+ cron = "@daily" ,
3302+ query = parse_one ("SELECT ds FROM test_model_a" ),
3303+ )
3304+ snapshot_b = make_snapshot (model_b , nodes = {model_a .fqn : model_a }, version = "1" )
3305+ snapshot_b .add_interval ("2020-01-01" , "2020-01-05" )
3306+
3307+ model_c = SqlModel (
3308+ name = "test_model_c" ,
3309+ kind = IncrementalByTimeRangeKind (
3310+ time_column = TimeColumn (column = "ds" ),
3311+ auto_restatement_cron = "0 10 * * *" ,
3312+ auto_restatement_intervals = 24 ,
3313+ ),
3314+ start = "2020-01-01" ,
3315+ cron = "@daily" ,
3316+ query = parse_one ("SELECT ds FROM test_model_a" ),
3317+ )
3318+ snapshot_c = make_snapshot (model_c , nodes = {model_a .fqn : model_a }, version = "1" )
3319+ snapshot_c .add_interval ("2020-01-01" , "2020-01-05" )
3320+ snapshot_c .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3321+
3322+ model_d = SqlModel (
3323+ name = "test_model_d" ,
3324+ kind = IncrementalByTimeRangeKind (
3325+ time_column = TimeColumn (column = "ds" ),
3326+ auto_restatement_cron = "0 10 * * *" ,
3327+ auto_restatement_intervals = 24 ,
3328+ ),
3329+ start = "2020-01-01" ,
3330+ cron = "@daily" ,
3331+ query = parse_one ("SELECT 1 as ds" ),
3332+ )
3333+ snapshot_d = make_snapshot (model_d , version = "1" )
3334+ snapshot_d .add_interval ("2020-01-01" , "2020-01-05" )
3335+ snapshot_d .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3336+
3337+ model_e = SqlModel (
3338+ name = "test_model_e" ,
3339+ kind = IncrementalByTimeRangeKind (
3340+ time_column = TimeColumn (column = "ds" ),
3341+ ),
3342+ start = "2020-01-01" ,
3343+ cron = "@daily" ,
3344+ query = parse_one (
3345+ "SELECT ds from test_model_b UNION ALL SELECT ds from test_model_c UNION ALL SELECT ds from test_model_d"
3346+ ),
3347+ )
3348+ snapshot_e = make_snapshot (
3349+ model_e ,
3350+ nodes = {
3351+ model_a .fqn : model_a ,
3352+ model_b .fqn : model_b ,
3353+ model_c .fqn : model_c ,
3354+ model_d .fqn : model_d ,
3355+ },
3356+ version = "1" ,
3357+ )
3358+ snapshot_e .add_interval ("2020-01-01" , "2020-01-05" )
3359+
3360+ _ , auto_restatement_triggers = apply_auto_restatements (
3361+ {
3362+ snapshot_a .snapshot_id : snapshot_a ,
3363+ snapshot_b .snapshot_id : snapshot_b ,
3364+ snapshot_c .snapshot_id : snapshot_c ,
3365+ snapshot_d .snapshot_id : snapshot_d ,
3366+ snapshot_e .snapshot_id : snapshot_e ,
3367+ },
3368+ "2020-01-06 10:01:00" ,
3369+ )
3370+
3371+ assert auto_restatement_triggers == {
3372+ snapshot_a .snapshot_id : [snapshot_a .snapshot_id ],
3373+ snapshot_d .snapshot_id : [snapshot_d .snapshot_id ],
3374+ snapshot_b .snapshot_id : [snapshot_a .snapshot_id ],
3375+ snapshot_c .snapshot_id : [snapshot_c .snapshot_id , snapshot_a .snapshot_id ],
3376+ snapshot_e .snapshot_id : [
3377+ snapshot_d .snapshot_id ,
3378+ snapshot_c .snapshot_id ,
3379+ snapshot_a .snapshot_id ,
3380+ ],
3381+ }
3382+
3383+
32793384def test_render_signal (make_snapshot , mocker ):
32803385 @signal ()
32813386 def check_types (batch , env : str , sql : list [SQL ], table : exp .Table , default : int = 0 ):
0 commit comments