forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAL01.yml
178 lines (163 loc) · 4.72 KB
/
AL01.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
rule: AL01
test_fail_default_explicit:
# Add whitespace when fixing implicit aliasing
fail_str: select foo.bar from table1 foo
fix_str: select foo.bar from table1 AS foo
test_fail_explicit:
# Add whitespace when fixing implicit aliasing
fail_str: select foo.bar from table1 foo
fix_str: select foo.bar from table1 AS foo
configs:
rules:
aliasing.table:
aliasing: explicit
test_fail_implicit:
# Add whitespace when fixing implicit aliasing
fail_str: select foo.bar from table1 AS foo
fix_str: select foo.bar from table1 foo
configs:
rules:
aliasing.table:
aliasing: implicit
test_fail_implicit_alias:
# Add whitespace when fixing implicit aliasing
fail_str: select foo.bar from (select 1 as bar)foo
fix_str: select foo.bar from (select 1 as bar) AS foo
test_fail_implicit_alias_space:
# No unnecessary whitespace added when fixing implicit aliasing
fail_str: select foo.bar from (select 1 as bar) foo
fix_str: select foo.bar from (select 1 as bar) AS foo
test_fail_implicit_alias_explicit:
# Test when explicitly setting explicit
fail_str: select foo.bar from (select 1 as bar) foo
fix_str: select foo.bar from (select 1 as bar) AS foo
configs:
rules:
aliasing.table:
aliasing: explicit
test_fail_implicit_alias_implicit:
# Test implicit
fail_str: select foo.bar from (select 1 as bar) AS foo
fix_str: select foo.bar from (select 1 as bar) foo
configs:
rules:
aliasing.table:
aliasing: implicit
test_fail_implicit_alias_implicit_multiple:
# Test implicit with multiple tables
fail_str: select foo.bar from (select 1 as bar) AS bar, (select 1 as foo) AS foo
fix_str: select foo.bar from (select 1 as bar) bar, (select 1 as foo) foo
configs:
rules:
aliasing.table:
aliasing: implicit
test_fail_implicit_alias_implicit_newline:
# NOTE: Even when removing by a newline, we should still remove any duplicate
# whitespace.
fail_str: |
select foo.bar from (select 1 as bar)
AS foo
fix_str: |
select foo.bar from (select 1 as bar)
foo
configs:
rules:
aliasing.table:
aliasing: implicit
test_fail_default_explicit_alias_merge:
# Add whitespace when fixing implicit aliasing
fail_str: |
MERGE dataset.inventory t
USING dataset.newarrivals s
ON t.product = s.product
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity;
fix_str: |
MERGE dataset.inventory AS t
USING dataset.newarrivals AS s
ON t.product = s.product
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity;
configs:
core:
dialect: bigquery
test_fail_explicit_alias_merge:
# Add whitespace when fixing implicit aliasing
fail_str: |
MERGE dataset.inventory t
USING dataset.newarrivals s
ON t.product = s.product
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity;
fix_str: |
MERGE dataset.inventory AS t
USING dataset.newarrivals AS s
ON t.product = s.product
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity;
configs:
core:
dialect: bigquery
rules:
aliasing.table:
aliasing: explicit
test_pass_implicit_alias_merge:
# Add whitespace when fixing implicit aliasing
pass_str: |
MERGE dataset.inventory t
USING dataset.newarrivals s
ON t.product = s.product
WHEN MATCHED THEN
UPDATE SET quantity = t.quantity + s.quantity;
configs:
core:
dialect: bigquery
rules:
aliasing.table:
aliasing: implicit
test_alias_expression_4492:
# Test failing alias expressions
# https://github.com/sqlfluff/sqlfluff/issues/4492
fail_str:
SELECT
voo.a
FROM foo voo
fix_str:
SELECT
voo.a
FROM foo AS voo
configs:
core:
dialect: snowflake
layout:
type:
alias_expression:
spacing_before: align
test_alias_expression_4089:
# Test failing alias expressions
# https://github.com/sqlfluff/sqlfluff/issues/4089
fail_str:
SELECT
RANK() OVER (PARTITION BY Id ORDER BY Id DESC) nr_rank
FROM (values ('Amsterdam', 1), ('London', 2)) Cities(Name, Id)
fix_str:
SELECT
RANK() OVER (PARTITION BY Id ORDER BY Id DESC) nr_rank
FROM (values ('Amsterdam', 1), ('London', 2)) AS Cities(Name, Id)
configs:
layout:
type:
alias_expression:
spacing_before: align
test_pass_alias_expression_oracle_tables:
# Test failing alias expressions
# https://github.com/sqlfluff/sqlfluff/issues/5038
# Skip aliasing with 'AS' for Oracle table expressions
pass_str:
SELECT
base.id,
base.customer_id
FROM {{ ref('customers') }} base
configs:
core:
dialect: oracle