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