@@ -2989,6 +2989,111 @@ def test_apply_auto_restatements_disable_restatement_downstream(make_snapshot):
29892989 ]
29902990
29912991
2992+ def test_auto_restatement_triggers (make_snapshot ):
2993+ model_a = SqlModel (
2994+ name = "test_model_a" ,
2995+ kind = IncrementalByTimeRangeKind (
2996+ time_column = TimeColumn (column = "ds" ),
2997+ auto_restatement_cron = "0 10 * * *" ,
2998+ auto_restatement_intervals = 24 ,
2999+ ),
3000+ start = "2020-01-01" ,
3001+ cron = "@daily" ,
3002+ query = parse_one ("SELECT 1 as ds" ),
3003+ )
3004+ snapshot_a = make_snapshot (model_a , version = "1" )
3005+ snapshot_a .add_interval ("2020-01-01" , "2020-01-05" )
3006+ snapshot_a .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3007+
3008+ model_b = SqlModel (
3009+ name = "test_model_b" ,
3010+ kind = IncrementalByTimeRangeKind (
3011+ time_column = TimeColumn (column = "ds" ),
3012+ ),
3013+ start = "2020-01-01" ,
3014+ cron = "@daily" ,
3015+ query = parse_one ("SELECT ds FROM test_model_a" ),
3016+ )
3017+ snapshot_b = make_snapshot (model_b , nodes = {model_a .fqn : model_a }, version = "1" )
3018+ snapshot_b .add_interval ("2020-01-01" , "2020-01-05" )
3019+
3020+ model_c = SqlModel (
3021+ name = "test_model_c" ,
3022+ kind = IncrementalByTimeRangeKind (
3023+ time_column = TimeColumn (column = "ds" ),
3024+ auto_restatement_cron = "0 10 * * *" ,
3025+ auto_restatement_intervals = 24 ,
3026+ ),
3027+ start = "2020-01-01" ,
3028+ cron = "@daily" ,
3029+ query = parse_one ("SELECT ds FROM test_model_a" ),
3030+ )
3031+ snapshot_c = make_snapshot (model_c , nodes = {model_a .fqn : model_a }, version = "1" )
3032+ snapshot_c .add_interval ("2020-01-01" , "2020-01-05" )
3033+ snapshot_c .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3034+
3035+ model_d = SqlModel (
3036+ name = "test_model_d" ,
3037+ kind = IncrementalByTimeRangeKind (
3038+ time_column = TimeColumn (column = "ds" ),
3039+ auto_restatement_cron = "0 10 * * *" ,
3040+ auto_restatement_intervals = 24 ,
3041+ ),
3042+ start = "2020-01-01" ,
3043+ cron = "@daily" ,
3044+ query = parse_one ("SELECT 1 as ds" ),
3045+ )
3046+ snapshot_d = make_snapshot (model_d , version = "1" )
3047+ snapshot_d .add_interval ("2020-01-01" , "2020-01-05" )
3048+ snapshot_d .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
3049+
3050+ model_e = SqlModel (
3051+ name = "test_model_e" ,
3052+ kind = IncrementalByTimeRangeKind (
3053+ time_column = TimeColumn (column = "ds" ),
3054+ ),
3055+ start = "2020-01-01" ,
3056+ cron = "@daily" ,
3057+ query = parse_one (
3058+ "SELECT ds from test_model_b UNION ALL SELECT ds from test_model_c UNION ALL SELECT ds from test_model_d"
3059+ ),
3060+ )
3061+ snapshot_e = make_snapshot (
3062+ model_e ,
3063+ nodes = {
3064+ model_a .fqn : model_a ,
3065+ model_b .fqn : model_b ,
3066+ model_c .fqn : model_c ,
3067+ model_d .fqn : model_d ,
3068+ },
3069+ version = "1" ,
3070+ )
3071+ snapshot_e .add_interval ("2020-01-01" , "2020-01-05" )
3072+
3073+ _ , auto_restatement_triggers = apply_auto_restatements (
3074+ {
3075+ snapshot_a .snapshot_id : snapshot_a ,
3076+ snapshot_b .snapshot_id : snapshot_b ,
3077+ snapshot_c .snapshot_id : snapshot_c ,
3078+ snapshot_d .snapshot_id : snapshot_d ,
3079+ snapshot_e .snapshot_id : snapshot_e ,
3080+ },
3081+ "2020-01-06 10:01:00" ,
3082+ )
3083+
3084+ assert auto_restatement_triggers == {
3085+ snapshot_a .snapshot_id : [snapshot_a .snapshot_id ],
3086+ snapshot_d .snapshot_id : [snapshot_d .snapshot_id ],
3087+ snapshot_b .snapshot_id : [snapshot_a .snapshot_id ],
3088+ snapshot_c .snapshot_id : [snapshot_c .snapshot_id , snapshot_a .snapshot_id ],
3089+ snapshot_e .snapshot_id : [
3090+ snapshot_d .snapshot_id ,
3091+ snapshot_c .snapshot_id ,
3092+ snapshot_a .snapshot_id ,
3093+ ],
3094+ }
3095+
3096+
29923097def test_render_signal (make_snapshot , mocker ):
29933098 @signal ()
29943099 def check_types (batch , env : str , sql : list [SQL ], table : exp .Table , default : int = 0 ):
0 commit comments