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