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