You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 0cbb9a7
Browse filesBrowse the repository at this point in the historyBrowse files
fix(rules): lint plain relation slot group reads in SQL macro bodies as bare columns
A plain read of a COLUMNS group stands as one bare column, as expansion pastes it, and every reference to one RELATION parameter as a relation shares one placeholder, so plain single-slot and undeclared reads through it are in scope. Real mixed-qualification and out-of-scope findings beside them are still reported.
expected_text:"CASE WHEN __sqlbuild_macro_parameter_0__ IN ('a', 'b') THEN 1 END + CASE WHEN __sqlbuild_macro_parameter_1__ IS NULL AND (__sqlbuild_macro_parameter_2__ IS NULL) THEN 1 END",
155
156
},
156
157
ParameterTestCase{
157
158
description:"SQL macro slot reads hide the slot name, whole after an alias",
158
159
body:"SELECT s.@src.amount AS amount, @src.id, @src.* FROM @src AS s",
expected_text:"SELECT s.__sqlbuild_macro_parameter_0__ AS amount, __sqlbuild_macro_parameter_1__.__sqlbuild_macro_parameter_2__, __sqlbuild_macro_parameter_3__.* FROM __sqlbuild_macro_parameter_4__ AS s",
161
162
},
162
163
ParameterTestCase{
163
164
description:"SQL macro calls, enum references and quoted text keep their at-signs",
description:"a plain group read is one bare value",
201
+
body:"SELECT @weekly.keys, orders FROM counted GROUP BY @weekly.keys",
202
+
expected_text:"SELECT __sqlbuild_macro_parameter_0__, orders FROM counted GROUP BY __sqlbuild_macro_parameter_1__",
203
+
},
204
+
SlotReadTestCase{
205
+
description:"plain single-slot and undeclared reads go through the one relation",
206
+
body:"SELECT @weekly.refund_count, @weekly.week FROM @weekly WHERE @cutoff > @cutoff",
207
+
expected_text:"SELECT __sqlbuild_macro_parameter_0__.__sqlbuild_macro_parameter_1__, __sqlbuild_macro_parameter_0__.__sqlbuild_macro_parameter_2__ FROM __sqlbuild_macro_parameter_0__ WHERE __sqlbuild_macro_parameter_3__ > __sqlbuild_macro_parameter_4__",
208
+
},
209
+
SlotReadTestCase{
210
+
description:"aliased reads stay whole after their alias",
211
+
body:"SELECT s.@weekly.keys, s.@weekly.refund_count FROM @weekly AS s",
212
+
expected_text:"SELECT s.__sqlbuild_macro_parameter_0__, s.__sqlbuild_macro_parameter_1__ FROM __sqlbuild_macro_parameter_2__ AS s",
213
+
},
214
+
];
215
+
216
+
for test_case in test_cases {
217
+
let source:String = format!("{header}{}\n", test_case.body);
218
+
let parameters = parse_sql_macro("weekly_rates","macros/sql/weekly_rates.sql",&source)
0 commit comments