forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRF01.yml
More file actions
307 lines (272 loc) · 6.98 KB
/
RF01.yml
File metadata and controls
307 lines (272 loc) · 6.98 KB
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
rule: RF01
test_pass_object_referenced_1:
# References in quotes in bigquery
pass_str: SELECT bar.user_id FROM `foo.far.bar`
configs:
core:
dialect: bigquery
rules:
references.from:
force_enable: true
test_fail_object_not_referenced_1:
desc: Name foo is not referenced in FROM clause. It would need to be at the end of identifier in ticks or an alias.
fail_str: SELECT foo.user_id FROM `foo.far.bar`
configs:
core:
dialect: bigquery
rules:
references.from:
force_enable: true
test_fail_object_not_referenced_2:
# References in WHERE clause
fail_str: SELECT * FROM my_tbl WHERE foo.bar > 0
test_pass_object_referenced_2:
pass_str: |
SELECT * FROM db.sc.tbl2
WHERE a NOT IN (SELECT a FROM db.sc.tbl1)
test_pass_object_referenced_3:
pass_str: |
SELECT * FROM db.sc.tbl2
WHERE a NOT IN (SELECT tbl2.a FROM db.sc.tbl1)
test_pass_object_referenced_4:
# Test ambiguous column reference caused by use of BigQuery structure fields.
# Here, 'et2' could either be a schema name or a table name.
# https://github.com/sqlfluff/sqlfluff/issues/1079
pass_str: |
SELECT et2.txn.amount
FROM `example_dataset2.example_table2` AS et2
configs:
core:
dialect: bigquery
rules:
references.from:
force_enable: true
test_pass_object_referenced_5a:
# Test ambiguous column reference caused by use of BigQuery structure fields.
# Here, column,field should not trigger the rule as by default this rule is
# disabled for bigquery
# https://github.com/sqlfluff/sqlfluff/issues/1503
pass_str: |
SELECT col1.field, col
FROM `example_dataset2.example_table2`
configs:
core:
dialect: bigquery
test_pass_object_referenced_5b:
# Same test as above but default (ANSI) should trigger
fail_str: |
SELECT col1.field
FROM table1
test_pass_object_referenced_5c:
# Same test as above but for BigQuery but force is
# enabled so should fail
fail_str: |
SELECT col1.field
FROM `example_dataset2.example_table2`
configs:
core:
dialect: bigquery
rules:
references.from:
force_enable: true
test_pass_object_referenced_5d:
# Test for extra dialect (hive) compatibility
pass_str: SELECT col1.field, col2 FROM example_table
configs:
core:
dialect: hive
test_pass_object_referenced_5e:
# Test for extra dialect (redshift) compatibility
pass_str: SELECT col1.field, col2 FROM example_table
configs:
core:
dialect: redshift
test_pass_object_referenced_6:
# Test references in subqueries (see issue #1939)
pass_str: |
select cc.c1
from (
select table1.c1
from
table1
inner join
table2
on table1.x_id = table2.x_id
inner join
table3
on table2.y_id = table3.y_id
) as cc
test_pass_object_referenced_7:
pass_str: |
UPDATE my_table
SET row_sum = (
SELECT COUNT(*) AS row_sum
FROM
another_table
WHERE
another_table.id = my_table.id
)
test_fail_object_referenced_7:
fail_str: |
UPDATE my_table
SET row_sum = (
SELECT COUNT(*) AS row_sum
FROM
another_table
WHERE
another_table.id = my_tableeee.id
)
test_pass_object_referenced_8:
pass_str: |
DELETE FROM agent1
WHERE EXISTS(
SELECT customer.cust_id FROM customer
WHERE agent1.agent_code <> customer.agent_code);
test_pass_two_part_reference_8:
pass_str: |
delete from public.agent1
where exists(
select customer.cust_id from customer
where agent1.agent_code <> customer.agent_code)
test_pass_two_part_reference_9:
pass_str: |
delete from public.agent1
where exists(
select customer.cust_id from customer
where public.agent1.agent_code <> customer.agent_code)
test_fail_two_part_reference_10:
fail_str: |
select *
from schema1.agent1
where schema2.agent1.agent_code <> 'abc'
test_fail_two_part_reference_11:
fail_str: |
delete from schema1.agent1
where exists(
select customer.cust_id from customer
where schema2.agent1.agent_code <> customer.agent_code)
test_pass_two_part_reference_11:
pass_str: |
select * from agent1
where public.agent1.agent_code <> '3'
test_pass_bigquery_dash:
# References in quotes in bigquery
pass_str: SELECT bar.user_id FROM foo-far.bar
configs:
core:
dialect: bigquery
rules:
references.from:
force_enable: true
test_pass_exasol_select_into:
pass_str: |
select *
into table schm.tab
from schm.tab2
configs:
core:
dialect: exasol
test_pass_simple_delete:
pass_str: |
delete from table1 where 1 = 1
test_exasol_invalid_foreign_key_from:
pass_str: |
SELECT *
WITH INVALID FOREIGN KEY (nr)
FROM T1 REFERENCING T2 (id)
configs:
core:
dialect: exasol
test_tsql_select_system_as_identifier:
pass_str: |
SELECT @@IDENTITY AS 'Identity'
configs:
core:
dialect: tsql
test_mysql_select_no_from_should_not_except:
pass_str: |
SELECT DATE_SUB('1992-12-31 23:59:59.000002', INTERVAL '1.999999' SECOND_MICROSECOND);
configs:
core:
dialect: mysql
test_nested_join_clause_does_not_flag:
pass_str: |
SELECT
1 AS RegionCode
FROM BA
LEFT OUTER JOIN I
LEFT OUTER JOIN P
ON I.Pcd = P.Iid
ON BA.Iid = I.Bcd
configs:
core:
dialect: tsql
test_nested_join_clauses_do_not_flag:
pass_str: |
SELECT
1 AS RegionCode
FROM BA
LEFT OUTER JOIN I
LEFT OUTER JOIN P
ON I.Pcd = P.Iid
LEFT OUTER JOIN C
ON I.Pcd = C.Iid
ON BA.Iid = I.Bcd
configs:
core:
dialect: tsql
test_parenthesized_join_clauses_do_not_flag:
pass_str: |
SELECT
1 AS RegionCode
FROM BA
LEFT OUTER JOIN (
I LEFT OUTER JOIN P
ON I.Pcd = P.Iid
) ON BA.Iid = I.Bcd
configs:
core:
dialect: tsql
test_soql_ignore_rule:
pass_str: |
SELECT Account.Name FROM Contact
configs:
core:
dialect: soql
test_postgres_value_table_alias:
pass_str: |
select
sc.col1 as colx
, pn.col1 as coly
from sch1.tbl1 as sc
cross join unnest(array[111, 222]) as pn(col1)
configs:
core:
dialect: postgres
test_pass_update_with_alias:
pass_str: |
UPDATE tbl AS dest SET
t.title = 'TEST'
WHERE t.id = 101 AND EXISTS (
SELECT 1 FROM foobar AS tmp WHERE tmp.idx = dest.idx)
test_pass_postgres_merge_with_alias:
pass_str: |
merge dw.sch.tbl dest
using land.sch.tbl src
on
src.idx = dest.idx
and src.name = dest.name
and src.idy = dest.idy
when not matched by source and exists
(
select 1 as tmp
from land.sch.tag as ld
where
ld.idx = dest.idx
and ld.name = dest.name
)
then update set
dest.ac = 'N'
configs:
core:
dialect: tsql