forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAL09.yml
More file actions
209 lines (202 loc) · 5.9 KB
/
Copy pathAL09.yml
File metadata and controls
209 lines (202 loc) · 5.9 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
rule: AL09
test_pass_no_self_alias:
# Test that the rule passes when there's no self alias.
pass_str: |
select
no_alias,
col_b as rename_alias,
max(sum) as max_sum
from foo
test_fail_no_quotes_same_case:
# When unquoted and the same case, we should always remove the alias.
fail_str: |
select
col_a as this_alias_is_fine,
col_b as col_b,
COL_C as COL_C,
Col_D as Col_D,
col_e col_e,
COL_F COL_F,
Col_G Col_G
from foo
fix_str: |
select
col_a as this_alias_is_fine,
col_b,
COL_C,
Col_D,
col_e,
COL_F,
Col_G
from foo
test_fail_with_quotes_same_case:
# When quoted and the same case, we should always remove the alias.
fail_str: |
select
"col_a" as "this_alias_is_fine",
"col_b" as "col_b",
"COL_C" as "COL_C",
"Col_D" as "Col_D",
"col_e" "col_e",
"COL_F" "COL_F",
"Col_G" "Col_G"
from foo
fix_str: |
select
"col_a" as "this_alias_is_fine",
"col_b",
"COL_C",
"Col_D",
"col_e",
"COL_F",
"Col_G"
from foo
test_fail_different_case:
# If the casing is different, even if the quoting is the same, we
# should never propose a fix. However in most dialects we should still
# flag the issue. If CP02 is active, this situation will be resolved
# before an error shows.
fail_str: |
select
col_a as this_alias_is_fine,
col_b as Col_B,
COL_C as col_c,
Col_D as COL_D,
col_e Col_e,
COL_F col_f,
Col_G COL_G,
"col_b" as "Col_B",
"COL_C" as "col_c",
"Col_D" as "COL_D",
"col_e" "Col_e",
"COL_F" "col_f",
"Col_G" "COL_G"
from foo
violations:
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 3
start_line_pos: 5
start_file_pos: 44
end_line_no: 3
end_line_pos: 10
end_file_pos: 49
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 4
start_line_pos: 5
start_file_pos: 64
end_line_no: 4
end_line_pos: 10
end_file_pos: 69
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 5
start_line_pos: 5
start_file_pos: 84
end_line_no: 5
end_line_pos: 10
end_file_pos: 89
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 6
start_line_pos: 5
start_file_pos: 104
end_line_no: 6
end_line_pos: 10
end_file_pos: 109
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 7
start_line_pos: 5
start_file_pos: 121
end_line_no: 7
end_line_pos: 10
end_file_pos: 126
- code: AL09
description: >-
Ambiguous self alias. Either remove unnecessary alias, or quote
alias/reference to make case change explicit.
name: aliasing.self_alias.column
warning: false
fixes: []
start_line_no: 8
start_line_pos: 5
start_file_pos: 138
end_line_no: 8
end_line_pos: 10
end_file_pos: 143
test_pass_different_case_clickhouse:
# If the casing is different, even if the quoting is the same, we
# should never propose a fix. In clickhouse, different cases are
# always different objects, even when unquoted - so never flag
# aliases as unnecessary if the casing is different.
pass_str: |
select
col_a as this_alias_is_fine,
col_b as Col_B,
COL_C as col_c,
Col_D as COL_D,
col_e Col_e,
COL_F col_f,
Col_G COL_G,
"col_b" as "Col_B",
"COL_C" as "col_c",
"Col_D" as "COL_D",
"col_e" "Col_e",
"COL_F" "col_f",
"Col_G" "COL_G"
from foo
configs:
core:
dialect: clickhouse
test_pass_different_quotes:
# If the quoting is different, even if the casing is the same, we
# should never fail/fix the rule. If RF06 changes the quoting we
# might trigger after that, but by then the quoting will be different.
pass_str: |
select
col_a as this_alias_is_fine,
"col_b" as col_b,
COL_C as "COL_C",
"Col_D" as Col_D,
col_e "col_e",
"COL_F" COL_F,
Col_G "Col_G"
from foo
test_pass_mysql_quoted_identifiers:
pass_str: |
SELECT
users.email AS "Email_in_double_quotes",
users.email AS "Email""with_escaped_double_quotes",
users.email AS `Email_in_backticks`,
users.email AS 'Email_in_single_quotes'
FROM users;
configs:
core:
dialect: mysql