forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LT01-excessive.yml
418 lines (379 loc) · 9.2 KB
/
LT01-excessive.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
rule: LT01
test_basic:
pass_str: SELECT 1
test_basic_template:
pass_str: |
{{ 'SELECT 1' }}
configs:
core:
ignore_templated_areas: false
test_basic_fix:
fail_str: SELECT 1
fix_str: SELECT 1
test_basic_fail_template:
fail_str: |
{{ 'SELECT 1' }}
configs:
core:
ignore_templated_areas: false
test_simple_fix:
fail_str: |
select
1 + 2 + 3 + 4 -- Comment
from foo
fix_str: |
select
1 + 2 + 3 + 4 -- Comment
from foo
test_identifier_fix:
fail_str: |
SELECT [thistable] . [col]
FROM [thisdatabase] . [thisschema]
. [thistable]
fix_str: |
SELECT [thistable].[col]
FROM [thisdatabase].[thisschema].[thistable]
configs:
core:
dialect: tsql
test_comparison_operator_fix:
fail_str: |
SELECT foo
FROM bar
WHERE baz > = 10;
fix_str: |
SELECT foo
FROM bar
WHERE baz >= 10;
configs:
core:
dialect: tsql
test_comparison_operator_pass:
pass_str: |
SELECT foo
FROM bar
WHERE baz >= 10;
configs:
core:
dialect: tsql
test_casting_operator_fix:
fail_str: |
SELECT '1' :: INT;
fix_str: |
SELECT '1'::INT;
configs:
core:
dialect: postgres
test_casting_operator_pass:
pass_str: |
SELECT '1'::INT;
configs:
core:
dialect: postgres
test_fix_tsql_spaced_chars:
fail_str: |
SELECT col1 FROM table1 WHERE 1 > = 1
fix_str: |
SELECT col1 FROM table1 WHERE 1 >= 1
configs:
core:
dialect: tsql
# Check CASE Statement parses with newlines properly
# See https://github.com/sqlfluff/sqlfluff/issues/2495
test_pass_postgres_case_statement:
pass_str: |
SELECT
a,
CASE
WHEN 1 THEN 'one'
WHEN 2 THEN 'two'
ELSE 'other'
END AS b
FROM test;
configs:
core:
dialect: postgres
test_excess_space_cast:
fail_str: |
select
'1' :: INT as id1,
'2'::int as id2
from table_a
fix_str: |
select
'1'::INT as id1,
'2'::int as id2
from table_a
test_redshift_at_time_zone:
pass_str: |
SELECT
date_w_tz[0] AT TIME ZONE 'Etc/UTC' AS bar
FROM foo
configs:
core:
dialect: redshift
test_pass_snowflake_semi_structured:
pass_str: "SELECT to_array(a.b:c) FROM d"
configs:
core:
dialect: snowflake
test_fail_snowflake_semi_structured_single:
fail_str: |
SELECT
to_array(a.b : c) as d,
e : f : g::string as h
FROM j
fix_str: |
SELECT
to_array(a.b:c) as d,
e:f:g::string as h
FROM j
configs:
core:
dialect: snowflake
test_fail_snowflake_semi_structured_multi:
fail_str: |
SELECT
to_array(a.b : c) as d,
e : f : g::string as h
FROM j
fix_str: |
SELECT
to_array(a.b:c) as d,
e:f:g::string as h
FROM j
configs:
core:
dialect: snowflake
test_pass_bigquery_specific:
# Test a selection of bigquery specific spacings work.
# Specifically EXCEPT & qualified functions.
pass_str: |
SELECT * EXCEPT (order_id);
SELECT NET.HOST(LOWER(url)) AS host FROM urls;
configs:
core:
dialect: bigquery
test_pass_bigquery_specific_arrays_1:
# An example of _no whitespace_ after an array type
pass_str: |
SELECT ARRAY<FLOAT64>[1, 2, 3] AS floats;
configs:
core:
dialect: bigquery
test_pass_bigquery_specific_arrays_2:
# An example of _whitespace_ after an array type
pass_str: |
CREATE TEMPORARY FUNCTION DoSomething(param1 STRING, param2 STRING)
RETURNS ARRAY<STRING> LANGUAGE js AS """Some JS""";
SELECT DoSomething(col1) FROM table1
configs:
core:
dialect: bigquery
test_pass_bigquery_array_function:
# Test spacing of Array Generator function brackets
pass_str: |
SELECT ARRAY(SELECT 1 FROM table1);
configs:
core:
dialect: bigquery
test_pass_bigquery_specific_structs:
# Test spacing of complex STRUCT brackets
pass_str: |
create table testing.array_struct_tbl (
address_array_of_nested_structs
ARRAY<STRUCT<coll STRUCT<col1_1 STRING, col1_2 INT64>, col2 STRING>>
)
configs:
core:
dialect: bigquery
test_pass_bigquery_specific_struct_access:
# Test spacing of function access
pass_str: |
SELECT
testFunction(a).b AS field,
testFunction(a).* AS wildcard,
testFunction(a).b.c AS field_with_field,
testFunction(a).b.* AS field_with_wildcard,
testFunction(a)[OFFSET(0)].* AS field_with_offset_wildcard,
testFunction(a)[SAFE_OFFSET(0)].* AS field_with_safe_offset_wildcard,
testFunction(a)[ORDINAL(1)].* AS field_with_ordinal_wildcard,
testFunction(a)[ORDINAL(1)].a AS field_with_ordinal_field
FROM table1
configs:
core:
dialect: bigquery
test_pass_bigquery_struct_function_no_spaces:
# Test struct function does not flag for missing spaces
# e.g. doesn't flag `STRUCT()` as should be `STRUCT ()`
pass_str: |
SELECT
TO_JSON(STRUCT()),
TO_JSON(STRUCT(1, 2, 3)),
STRUCT(1, 2, 3)
FROM
table1
configs:
core:
dialect: bigquery
test_postgres_datatype:
# https://github.com/sqlfluff/sqlfluff/issues/4521
# https://github.com/sqlfluff/sqlfluff/issues/4565
pass_str: |
select
1::NUMERIC(3, 1),
2::double precision,
'2020-01-01'::timestamp with time zone,
'foo'::character varying,
B'10101'::bit(3),
B'10101'::bit varying(3),
B'10101'::bit varying
configs:
core:
dialect: postgres
test_redshift_datatype:
pass_str: |
select
1::NUMERIC(3, 1),
2::double precision,
'2020-01-01'::timestamp with time zone,
'foo'::character varying,
'foo'::character varying(MAX),
'foo'::character varying(255),
'10101'::binary varying(6)
configs:
core:
dialect: redshift
test_bigquery_datatype:
pass_str: |
select 1::NUMERIC(3, 1)
configs:
core:
dialect: bigquery
test_athena_datatype:
pass_str: |
select
1::DECIMAL(3, 1),
'foo'::VARCHAR(4),
'bar'::CHAR(3),
col1::STRUCT<foo: int>,
col2::ARRAY<int>,
'2020-01-01'::timestamp with time zone
configs:
core:
dialect: athena
test_hive_datatype:
pass_str: |
select
1::DECIMAL(3, 1),
1::DEC(3, 1),
1::NUMERIC(3, 1),
col1::STRUCT<foo: int>,
col2::ARRAY<int>,
col3::ARRAY<int>[4]
configs:
core:
dialect: hive
test_sqlite_datatype:
pass_str: |
select
1::double precision,
1::DECIMAL(10, 5),
1::unsigned big int,
'foo'::varying character(255),
'foo'::character(20),
'foo'::nvarchar(200)
configs:
core:
dialect: sqlite
test_sparksql_datatype:
pass_str: |
select
1::DECIMAL(3, 1),
1::DEC(3, 1),
1::NUMERIC(3, 1),
'bar'::CHAR(3),
col1::STRUCT<foo: int>,
col2::ARRAY<int>
configs:
core:
dialect: sparksql
test_exasol_datatype:
pass_str: |
select
1::double precision,
1::DECIMAL(3, 1),
1::NUMERIC(3, 1),
'bar'::VARCHAR(2000 CHAR),
col1::INTERVAL DAY(2) TO SECOND(1)
configs:
core:
dialect: exasol
test_teradata_datatype:
pass_str: |
select
1::DECIMAL(3, 1),
1::DEC(3, 1),
1::NUMERIC(3, 1),
'bar'::CHAR(3)
configs:
core:
dialect: teradata
test_tsql_datatype:
pass_str: |
select
1::DECIMAL(3, 1),
1::DEC(3, 1),
1::NUMERIC(3, 1),
'bar'::character varying(3)
configs:
core:
dialect: tsql
test_snowflake_match_pattern:
# Check that the spacing within the pattern isn't changed.
# The MATCH_RECOGNIZE & PATTERN keywords however act as keywords and not as functions
# therefore _should_ have a space after them.
# See: https://docs.snowflake.com/en/sql-reference/constructs/match_recognize
pass_str: |
select * from stock_price_history
match_recognize (
partition by company
order by price_date
measures
match_number() as match_number,
first(price_date) as start_date,
last(price_date) as end_date,
count(*) as rows_in_sequence,
count(row_with_price_decrease.*) as num_decreases,
count(row_with_price_increase.*) as num_increases
one row per match
after match skip to last row_with_price_increase
pattern ((A | B){5} C+)
define
row_with_price_decrease as price < lag(price),
row_with_price_increase as price > lag(price)
)
order by company, match_number;
configs:
core:
dialect: snowflake
test_hive_set_statement:
# This should use ColonDelimiter so it shouldn't have spacing around it.
pass_str: |
set hivevar:cat = "Chloe";
configs:
core:
dialect: hive
test_spark_set_statement:
pass_str: |
SET -v;
configs:
core:
dialect: sparksql
test_clickhouse_system_path:
# We shouldn't introduce extra spaces within the path.
pass_str: |
SYSTEM RELOAD MODEL /model/path;
configs:
core:
dialect: clickhouse