@@ -2590,3 +2590,72 @@ def test_apply_auto_restatements(make_snapshot):
25902590 assert snapshot_f .intervals == [
25912591 (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-06" )),
25922592 ]
2593+
2594+
2595+ def test_apply_auto_restatements_disable_restatement_downstream (make_snapshot ):
2596+ # Hourly upstream model with auto restatement intervals set to 24
2597+ model_a = SqlModel (
2598+ name = "test_model_a" ,
2599+ kind = IncrementalByTimeRangeKind (
2600+ time_column = TimeColumn (column = "ds" ),
2601+ auto_restatement_cron = "0 10 * * *" ,
2602+ auto_restatement_intervals = 24 ,
2603+ ),
2604+ cron = "@hourly" ,
2605+ query = parse_one ("SELECT 1, ds FROM name" ),
2606+ )
2607+ snapshot_a = make_snapshot (model_a , version = "1" )
2608+ snapshot_a .add_interval ("2020-01-01" , "2020-01-06 09:00:00" )
2609+ snapshot_a .next_auto_restatement_ts = to_timestamp ("2020-01-06 10:00:00" )
2610+
2611+ # Daily downstream model with disable restatement
2612+ model_b = SqlModel (
2613+ name = "test_model_b" ,
2614+ kind = IncrementalByTimeRangeKind (
2615+ time_column = TimeColumn (column = "ds" ),
2616+ disable_restatement = True ,
2617+ ),
2618+ cron = "@daily" ,
2619+ query = parse_one ("SELECT ds FROM test_model_a" ),
2620+ )
2621+ snapshot_b = make_snapshot (model_b , nodes = {model_a .fqn : model_a }, version = "2" )
2622+ snapshot_b .add_interval ("2020-01-01" , "2020-01-05" )
2623+ assert snapshot_a .snapshot_id in snapshot_b .parents
2624+
2625+ restated_intervals = apply_auto_restatements (
2626+ {
2627+ snapshot_a .snapshot_id : snapshot_a ,
2628+ snapshot_b .snapshot_id : snapshot_b ,
2629+ },
2630+ "2020-01-06 10:01:00" ,
2631+ )
2632+ assert sorted (restated_intervals , key = lambda x : x .name ) == [
2633+ SnapshotIntervals (
2634+ name = snapshot_a .name ,
2635+ identifier = snapshot_a .identifier ,
2636+ version = snapshot_a .version ,
2637+ intervals = [],
2638+ dev_intervals = [],
2639+ pending_restatement_intervals = [
2640+ (to_timestamp ("2020-01-05 10:00:00" ), to_timestamp ("2020-01-06 10:00:00" ))
2641+ ],
2642+ ),
2643+ ]
2644+
2645+ assert snapshot_a .next_auto_restatement_ts == to_timestamp ("2020-01-07 10:00:00" )
2646+ assert snapshot_b .next_auto_restatement_ts is None
2647+
2648+ assert snapshot_a .intervals == [
2649+ (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-05 10:00:00" )),
2650+ ]
2651+ assert snapshot_b .intervals == [
2652+ (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-06" )),
2653+ ]
2654+
2655+ snapshot_b .pending_restatement_intervals = [
2656+ (to_timestamp ("2020-01-03" ), to_timestamp ("2020-01-06" ))
2657+ ]
2658+ snapshot_b .apply_pending_restatement_intervals ()
2659+ assert snapshot_b .intervals == [
2660+ (to_timestamp ("2020-01-01" ), to_timestamp ("2020-01-06" )),
2661+ ]
0 commit comments