26
26
"only_skip_backfill" ,
27
27
],
28
28
)
29
- @pytest .mark .skip (reason = "Work in progress test" )
29
+ # @pytest.mark.skip(reason="Work in progress test")
30
30
def test_given_model_chain_when_running_with_different_flags_then_behaves_as_expected (
31
- model_change_test_context : SQLMeshTestContext ,
31
+ sample_sqlmesh_test_context : SQLMeshTestContext ,
32
32
no_auto_upstream : bool ,
33
33
skip_backfill : bool ,
34
34
expected_changes : dict [str , str ],
@@ -55,175 +55,86 @@ def test_given_model_chain_when_running_with_different_flags_then_behaves_as_exp
55
55
">=" means final count should be greater than or equal to initial
56
56
"""
57
57
# Initial run to set up all models
58
- # model_change_test_context.plan_and_run(
59
- # environment="dev",
60
- # start="2023-02-01",
61
- # end="2023-02-03",
62
- # plan_options=PlanOptions(
63
- # execution_time="2023-02-03",
64
- # ),
65
- # run_options=RunOptions(
66
- # execution_time="2023-02-03",
67
- # ),
68
- # )
69
-
70
- # # Get initial counts for the model chain
71
- # initial_counts = {
72
- # "staging_1": model_change_test_context.query(
73
- # "SELECT COUNT(*) FROM sqlmesh_example__dev.staging_model_1"
74
- # )[0][0],
75
- # "staging_2": model_change_test_context.query(
76
- # "SELECT COUNT(*) FROM sqlmesh_example__dev.staging_model_2"
77
- # )[0][0],
78
- # "intermediate": model_change_test_context.query(
79
- # "SELECT COUNT(*) FROM sqlmesh_example__dev.intermediate_model_1"
80
- # )[0][0],
81
- # "full": model_change_test_context.query(
82
- # "SELECT COUNT(*) FROM sqlmesh_example__dev.full_model"
83
- # )[0][0],
84
- # }
85
-
86
- # print(f"initial_counts: {initial_counts}")
87
- # print(
88
- # f"intermediate_model_1 first run: {
89
- # model_change_test_context.query(
90
- # 'SELECT * FROM sqlmesh_example__dev.intermediate_model_1',
91
- # return_df=True,
92
- # )
93
- # }"
94
- # )
95
-
96
- # # Modify staging_model_1 to include more data
97
- # model_change_test_context.modify_model_file(
98
- # "intermediate_model_1.sql",
99
- # """
100
- # MODEL (
101
- # name sqlmesh_example.intermediate_model_1,
102
- # kind INCREMENTAL_BY_TIME_RANGE (
103
- # time_column event_date
104
- # ),
105
- # start '2020-01-01',
106
- # cron '@daily',
107
- # grain (id, event_date)
108
- # );
109
-
110
- # SELECT
111
- # main.id,
112
- # main.item_id,
113
- # main.event_date,
114
- # CONCAT(sub.item_name, ' - modified18') as item_name
115
- # FROM sqlmesh_example.staging_model_1 AS main
116
- # INNER JOIN sqlmesh_example.staging_model_2 as sub
117
- # ON main.id = sub.id
118
- # WHERE
119
- # event_date BETWEEN @start_date AND @end_date
120
-
121
- # """,
122
- # )
123
-
124
- # raise Exception("Stop here")
58
+ sample_sqlmesh_test_context .plan_and_run (
59
+ environment = "dev" ,
60
+ )
61
+
62
+
63
+ print (
64
+ f"intermediate_model_1 first run: {
65
+ sample_sqlmesh_test_context .query (
66
+ 'SELECT * FROM sqlmesh_example__dev.intermediate_model_1' ,
67
+ return_df = True ,
68
+ )
69
+ } "
70
+ )
71
+ print (
72
+ f"full_model first run: {
73
+ sample_sqlmesh_test_context .query (
74
+ 'SELECT * FROM sqlmesh_example__dev.full_model' ,
75
+ return_df = True ,
76
+ )
77
+ } "
78
+ )
79
+
80
+ # # Modify intermediate_model_1 sql to cause breaking change
81
+ sample_sqlmesh_test_context .modify_model_file (
82
+ "intermediate_model_1.sql" ,
83
+ """
84
+ MODEL (
85
+ name sqlmesh_example.intermediate_model_1,
86
+ kind INCREMENTAL_BY_TIME_RANGE (
87
+ time_column event_date
88
+ ),
89
+ start '2020-01-01',
90
+ cron '@daily',
91
+ grain (id, event_date)
92
+ );
93
+
94
+ SELECT
95
+ main.id,
96
+ main.item_id,
97
+ main.event_date,
98
+ CONCAT(sub.item_name, ' - modified1') as item_name
99
+ FROM sqlmesh_example.staging_model_1 AS main
100
+ INNER JOIN sqlmesh_example.staging_model_2 as sub
101
+ ON main.id = sub.id
102
+ WHERE
103
+ event_date BETWEEN @start_date AND @end_date
104
+
105
+ """ ,
106
+ )
107
+
125
108
126
109
# Run with specified flags
127
- model_change_test_context .plan_and_run (
110
+ sample_sqlmesh_test_context .plan_and_run (
128
111
environment = "dev" ,
129
112
plan_options = PlanOptions (
130
113
skip_backfill = skip_backfill ,
131
114
enable_preview = True ,
132
115
),
133
- select_models = ["sqlmesh_example.intermediate_model_1" ],
134
116
)
135
117
136
- # Get final counts and debug info
137
- final_counts = {
138
- "seed_1" : model_change_test_context .query (
139
- "SELECT COUNT(*) FROM sqlmesh_example__dev.seed_model_1"
140
- )[0 ][0 ],
141
- "staging_1" : model_change_test_context .query (
142
- "SELECT COUNT(*) FROM sqlmesh_example__dev.staging_model_1"
143
- )[0 ][0 ],
144
- "staging_2" : model_change_test_context .query (
145
- "SELECT COUNT(*) FROM sqlmesh_example__dev.staging_model_2"
146
- )[0 ][0 ],
147
- "intermediate" : model_change_test_context .query (
148
- "SELECT COUNT(*) FROM sqlmesh_example__dev.intermediate_model_1"
149
- )[0 ][0 ],
150
- "full" : model_change_test_context .query (
151
- "SELECT COUNT(*) FROM sqlmesh_example__dev.full_model"
152
- )[0 ][0 ],
153
- }
154
- print (f"first_model_change_counts: { final_counts } " )
155
- # print(
156
- # f"intermediate_model_1 after first model change to upstream model: {
157
- # model_change_test_context.query(
158
- # 'SELECT * FROM sqlmesh_example__dev.intermediate_model_1',
159
- # return_df=True,
160
- # )
161
- # }"
162
- # )
163
-
164
- # # Modify staging_model_1 to include more data
165
- # model_change_test_context.modify_model_file(
166
- # "staging_model_2.sql",
167
- # """
168
- # MODEL (
169
- # name sqlmesh_example.staging_model_2,
170
- # grain id
171
- # );
172
-
173
- # SELECT
174
- # id,
175
- # CONCAT(item_name, ' - modified again') as item_name
176
- # FROM
177
- # sqlmesh_example.seed_model_2
178
- # """,
179
- # )
180
-
181
- # # Run with specified flags
182
- # model_change_test_context.plan_and_run(
183
- # environment="dev",
184
- # start="2023-02-01",
185
- # end="2023-02-03",
186
- # execution_time="2023-02-03",
187
- # plan_options=PlanOptions(
188
- # select_models=[
189
- # "sqlmesh_example.staging_model_2",
190
- # ],
191
- # skip_backfill=skip_backfill,
192
- # enable_preview=True,
193
- # ),
194
- # # run_options=RunOptions(
195
- # # select_models=[
196
- # # "sqlmesh_example.staging_model_1",
197
- # # ],
198
- # # no_auto_upstream=no_auto_upstream,
199
- # # ),
200
- # )
201
-
202
- # print(
203
- # f"intermediate_model_1 after second model change to upstream model: {
204
- # model_change_test_context.query(
205
- # 'SELECT * FROM sqlmesh_example__dev.intermediate_model_1',
206
- # return_df=True,
207
- # )
208
- # }"
209
- # )
118
+ print (
119
+ f"intermediate_model_1 after first model change to upstream model: {
120
+ sample_sqlmesh_test_context .query (
121
+ 'SELECT * FROM sqlmesh_example__dev.intermediate_model_1' ,
122
+ return_df = True ,
123
+ )
124
+ } "
125
+ )
126
+
127
+ print (
128
+ f"full_model after first model change to upstream model: {
129
+ sample_sqlmesh_test_context .query (
130
+ 'SELECT * FROM sqlmesh_example__dev.full_model' ,
131
+ return_df = True ,
132
+ )
133
+ } "
134
+ )
210
135
211
136
raise Exception ("Stop here" )
212
137
213
- # # Verify counts match expectations
214
- # for model, expected_change in expected_changes.items():
215
- # if expected_change == "==":
216
- # assert final_counts[model] == initial_counts[model], (
217
- # f"{model} count should remain unchanged when "
218
- # f"no_auto_upstream={no_auto_upstream} and skip_backfill={skip_backfill}"
219
- # )
220
- # elif expected_change == ">=":
221
- # assert final_counts[model] >= initial_counts[model], (
222
- # f"{model} count should increase when "
223
- # f"no_auto_upstream={no_auto_upstream} and skip_backfill={skip_backfill}"
224
- # )
225
- # else:
226
- # raise ValueError(f"Invalid expected change: {expected_change}")
227
138
228
139
229
140
if __name__ == "__main__" :
0 commit comments