forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathST02.yml
276 lines (268 loc) · 6.04 KB
/
ST02.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
rule: ST02
test_pass_case_cannot_be_reduced_1:
pass_str: |
select
fab > 0 as is_fab
from fancy_table
test_pass_case_cannot_be_reduced_2:
pass_str: |
select
case when fab > 0 then true end as is_fab
from fancy_table
test_pass_case_cannot_be_reduced_3:
pass_str: |
select
case when fab is not null then false end as is_fab
from fancy_table
test_pass_case_cannot_be_reduced_4:
pass_str: |
select
case when fab > 0 then true else true end as is_fab
from fancy_table
test_pass_case_cannot_be_reduced_5:
pass_str: |
select
case when fab <> 0 then 'just a string' end as fab_category
from fancy_table
test_pass_case_cannot_be_reduced_6:
pass_str: |
select
case
when fab <> 0 then true
when fab < 0 then 'not a bool'
end as fab_category
from fancy_table
test_pass_case_cannot_be_reduced_7:
pass_str: |
select
foo,
case
when
bar is null then bar
else '123'
end as test
from baz;
test_pass_case_cannot_be_reduced_8:
pass_str: |
select
foo,
case
when
bar is not null then '123'
else bar
end as test
from baz;
test_pass_case_cannot_be_reduced_9:
pass_str: |
select
foo,
case
when
bar is not null then '123'
when
foo is not null then '456'
else bar
end as test
from baz;
test_pass_case_cannot_be_reduced_10:
pass_str: |
select
foo,
case
when
bar is not null and abs(foo) > 0 then '123'
else bar
end as test
from baz;
test_pass_case_cannot_be_reduced_11:
pass_str: |
SELECT
dv_runid,
CASE
WHEN LEAD(dv_startdateutc) OVER (
PARTITION BY rowid ORDER BY dv_startdateutc
) IS NULL
THEN 1
ELSE 0
END AS loadstate
FROM d;
test_pass_case_cannot_be_reduced_12:
pass_str: |
select
field_1,
field_2,
field_3,
case
when coalesce(field_2, field_3) is null then 1 else 0
end as field_4
from my_table;
test_pass_case_cannot_be_reduced_13:
pass_str: |
SELECT
CASE
WHEN item.submitted_timestamp IS NOT NULL
THEN item.sitting_id
END
configs:
core:
dialect: postgres
test_fail_unnecessary_case_1:
fail_str: |
select
case
when fab > 0 then true else false end as is_fab
from fancy_table
fix_str: |
select
coalesce(fab > 0, false) as is_fab
from fancy_table
test_fail_unnecessary_case_2:
fail_str: |
select
case
when fab > 0 then false else true end as is_fab
from fancy_table
fix_str: |
select
not coalesce(fab > 0, false) as is_fab
from fancy_table
test_fail_unnecessary_case_3:
fail_str: |
select
case
when fab > 0 and tot > 0 then true else false end as is_fab
from fancy_table
fix_str: |
select
coalesce(fab > 0 and tot > 0, false) as is_fab
from fancy_table
test_fail_unnecessary_case_4:
fail_str: |
select
case
when fab > 0 and tot > 0 then false else true end as is_fab
from fancy_table
fix_str: |
select
not coalesce(fab > 0 and tot > 0, false) as is_fab
from fancy_table
test_fail_unnecessary_case_5:
fail_str: |
select
case
when not fab > 0 or tot > 0 then false else true end as is_fab
from fancy_table
fix_str: |
select
not coalesce(not fab > 0 or tot > 0, false) as is_fab
from fancy_table
test_fail_unnecessary_case_6:
fail_str: |
select
subscriptions_xf.metadata_migrated,
case -- BEFORE ST02 FIX
when perks.perk is null then false
else true
end as perk_redeemed,
perks.received_at as perk_received_at
from subscriptions_xf
fix_str: |
select
subscriptions_xf.metadata_migrated,
not coalesce(perks.perk is null, false) as perk_redeemed,
perks.received_at as perk_received_at
from subscriptions_xf
test_fail_unnecessary_case_7:
fail_str: |
select
foo,
case
when
bar is null then '123'
else bar
end as test
from baz;
fix_str: |
select
foo,
coalesce(bar, '123') as test
from baz;
test_fail_unnecessary_case_8:
fail_str: |
select
foo,
case
when
bar is not null then bar
else '123'
end as test
from baz;
fix_str: |
select
foo,
coalesce(bar, '123') as test
from baz;
test_fail_unnecessary_case_9:
fail_str: |
select
foo,
case
when
bar is null then null
else bar
end as test
from baz;
fix_str: |
select
foo,
bar as test
from baz;
test_fail_unnecessary_case_10:
fail_str: |
select
foo,
case
when
bar is not null then bar
else null
end as test
from baz;
fix_str: |
select
foo,
bar as test
from baz;
test_fail_unnecessary_case_11:
fail_str: |
select
foo,
case
when
bar is not null then bar
end as test
from baz;
fix_str: |
select
foo,
bar as test
from baz;
test_fail_no_copy_code_out_of_template:
# The rule wants to replace the case statement with coalesce(), but
# LintFix.has_template_conflicts() correctly prevents it copying code out
# of the templated region. Hence, the query is not modified.
fail_str: |
select
foo,
case
when
bar is null then {{ result }}
else bar
end as test
from baz;
configs:
core:
ignore_templated_areas: false
templater:
jinja:
context:
result: "'123'"