forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LT09.yml
385 lines (345 loc) · 7.57 KB
/
LT09.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
rule: LT09
test_single_select_target_and_no_newline_between_select_and_select_target:
pass_str: select a from x
test_single_wildcard_select_target_and_no_newline_between_select_and_select_target_1:
fail_str: |
select * from x
fix_str: |
select
*
from x
configs:
rules:
layout.select_targets:
wildcard_policy: multiple
test_single_wildcard_select_target_and_no_newline_between_select_and_select_target_2:
pass_str: |
select * from x
test_single_select_target_and_newline_after_select_target_1:
pass_str: |
select *
from x
test_single_select_target_and_newline_after_select_target_2:
fail_str: |
select *
from x
fix_str: |
select
*
from x
configs:
rules:
layout.select_targets:
wildcard_policy: multiple
test_single_select_target_and_newline_before_select_target:
fail_str: |
select
a
from x
fix_str: |
select a
from x
test_multiple_select_targets_on_newlines_and_newline_after_select:
pass_str: |
select
a,
b,
c
from x
test_single_wildcard_select_target_and_newline_before_select_target_1:
pass_str: |
select *
from x
test_single_wildcard_select_target_and_newline_before_select_target_2:
pass_str: |
select
*
from x
configs:
rules:
layout.select_targets:
wildcard_policy: multiple
test_single_wildcard_select_target_and_newline_before_select_target_plus_from_on_same_line_1:
fail_str: |
select
* from x
fix_str: |
select
*
from x
configs:
rules:
layout.select_targets:
wildcard_policy: multiple
test_single_wildcard_select_target_and_newline_before_select_target_plus_from_on_same_line_2:
fail_str: |
select
* from x
fix_str: |
select *
from x
test_multiple_select_targets_all_on_the_same_line:
fail_str: |
select a, b, c
from x
fix_str: "select\na,\nb,\nc\nfrom x\n"
test_multiple_select_targets_all_on_the_same_line_plus_from_clause:
fail_str: |
select a, b, c from x
fix_str: "select\na,\nb,\nc\nfrom x\n"
test_multiple_select_targets_including_wildcard_all_on_the_same_line_plus_from_clause:
fail_str: |
select *, b, c from x
fix_str: "select\n*,\nb,\nc\nfrom x\n"
test_multiple_select_target_plus_from_clause_on_the_same_line:
fail_str: |
select
a,
b,
c from x
fix_str: |
select
a,
b,
c
from x
test_multiple_select_targets_trailing_whitespace_after_select:
# TRICKY: Use explicit newlines to preserve the trailing space after "SELECT".
pass_str: "SELECT \n a,\n b\nFROM t\n"
test_single_select_with_comment_after_select:
# Currently not autofixed because dealing with the comment is tricky.
# Could be supported later.
fail_str: |
SELECT --some comment
a
test_comment_between_select_and_single_select_target:
fail_str: |
SELECT
-- This is the user's ID.
user_id
FROM
safe_user
fix_str: |
SELECT user_id
-- This is the user's ID.
FROM
safe_user
test_multiple_select_targets_some_newlines_missing_1:
fail_str: |
select
a, b, c,
d, e, f, g,
h
from x
# The spaces before a, d, and h look odd, but these are places where the
# select targets were already on a separate line, and the rule made no
# changes.
fix_str: |
select
a,
b,
c,
d,
e,
f,
g,
h
from x
test_multiple_select_targets_some_newlines_missing_2:
fail_str: |
select a, b, c,
d, e, f, g,
h
from x
# The spaces before d, and h look odd, but these are places where the
# select targets were already on a separate line, and the rule made no
# changes.
fix_str: |
select
a,
b,
c,
d,
e,
f,
g,
h
from x
test_cte:
fail_str: |
WITH
cte1 AS (
SELECT
c1 AS c
FROM
t
)
SELECT 1
FROM cte1
fix_str: |
WITH
cte1 AS (
SELECT c1 AS c
FROM
t
)
SELECT 1
FROM cte1
test_single_newline_no_from:
fail_str: |
SELECT
id
fix_str: |
SELECT id
test_single_distinct_no_from:
fail_str: |
SELECT
DISTINCT id
fix_str: |
SELECT DISTINCT id
test_distinct_many:
fail_str: |
SELECT distinct a, b, c
FROM my_table
fix_str: |
SELECT distinct
a,
b,
c
FROM my_table
test_distinct_single_pass:
pass_str: |
SELECT distinct a
FROM my_table
test_distinct_single_fail_a:
fail_str: |
SELECT distinct
a
FROM my_table
fix_str: |
SELECT distinct a
FROM my_table
test_distinct_single_fail_b:
fail_str: |
SELECT
distinct a
FROM my_table
fix_str: |
SELECT distinct a
FROM my_table
test_single_select_with_no_from:
fail_str: "SELECT\n 10000000\n"
fix_str: "SELECT 10000000\n"
test_single_select_with_no_from_previous_comment:
fail_str: "SELECT\n /* test */ 10000000\n"
fix_str: "SELECT 10000000 /* test */\n"
test_single_select_with_comment_after_column:
fail_str: |
SELECT
1 -- this is a comment
FROM
my_table
fix_str: |
SELECT 1
-- this is a comment
FROM
my_table
test_single_select_with_comment_after_column_no_space:
fail_str: |
SELECT
1-- this is a comment
FROM
my_table
fix_str: |
SELECT 1
-- this is a comment
FROM
my_table
test_single_select_with_multiple_mixed_comments:
fail_str: |
SELECT
-- previous comment
1 -- this is a comment
FROM
my_table
fix_str: |
SELECT 1
-- previous comment
-- this is a comment
FROM
my_table
test_single_select_with_comment before:
fail_str: |
SELECT
/* comment before */ 1
FROM
my_table
fix_str: |
SELECT 1
/* comment before */
FROM
my_table
test_create_view:
fail_str: |
CREATE VIEW a
AS
SELECT
c
FROM table1
INNER JOIN table2 ON (table1.id = table2.id);
fix_str: |
CREATE VIEW a
AS
SELECT c
FROM table1
INNER JOIN table2 ON (table1.id = table2.id);
test_multiline_single:
# https://github.com/sqlfluff/sqlfluff/issues/4516
pass_str: |
SELECT
SUM(
1 + SUM(
2 + 3
)
) AS col
FROM test_table
test_multiline_expressions:
# NOTE: LT09 doesn't fix the indentation, so that may still look strange here,
# but we should make sure we're inserting new line breaks in the right places.
# https://github.com/sqlfluff/sqlfluff/issues/5258
fail_str: |
SELECT
a,
b1, b2,
COUNT(DISTINCT id) AS c1, COUNT(DISTINCT name) AS c2, COUNT(DISTINCT city) AS c3,
COUNT(
DISTINCT id) AS d1, COUNT(DISTINCT name) AS d2, COUNT(DISTINCT city) AS d3,
COUNT(DISTINCT
id) AS e1, COUNT(DISTINCT name) AS e2, COUNT(DISTINCT city) AS e3
FROM some_table;
fix_str: |
SELECT
a,
b1,
b2,
COUNT(DISTINCT id) AS c1,
COUNT(DISTINCT name) AS c2,
COUNT(DISTINCT city) AS c3,
COUNT(
DISTINCT id) AS d1,
COUNT(DISTINCT name) AS d2,
COUNT(DISTINCT city) AS d3,
COUNT(DISTINCT
id) AS e1,
COUNT(DISTINCT name) AS e2,
COUNT(DISTINCT city) AS e3
FROM some_table;
test_pass_leading_commas:
# https://github.com/sqlfluff/sqlfluff/issues/5329
# NOTE: We shouldn't even need to configure the leading commas here.
# Commas shouldn't be accounted for in whether elements are on the same line.
pass_str: |
select
a
, b
, c