Skip to content

Commit 647b98d

Browse files
fix(starrocks): Add RESERVED_KEYWORDS specific to starrocks (#4402)
Co-authored-by: Alexey Yesis <[email protected]>
1 parent 9694999 commit 647b98d

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

sqlglot/dialects/starrocks.py

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,161 @@ class Generator(MySQL.Generator):
112112

113113
TRANSFORMS.pop(exp.DateTrunc)
114114

115+
# https://docs.starrocks.io/docs/sql-reference/sql-statements/keywords/#reserved-keywords
116+
RESERVED_KEYWORDS = {
117+
"add",
118+
"all",
119+
"alter",
120+
"analyze",
121+
"and",
122+
"array",
123+
"as",
124+
"asc",
125+
"between",
126+
"bigint",
127+
"bitmap",
128+
"both",
129+
"by",
130+
"case",
131+
"char",
132+
"character",
133+
"check",
134+
"collate",
135+
"column",
136+
"compaction",
137+
"convert",
138+
"create",
139+
"cross",
140+
"cube",
141+
"current_date",
142+
"current_role",
143+
"current_time",
144+
"current_timestamp",
145+
"current_user",
146+
"database",
147+
"databases",
148+
"decimal",
149+
"decimalv2",
150+
"decimal32",
151+
"decimal64",
152+
"decimal128",
153+
"default",
154+
"deferred",
155+
"delete",
156+
"dense_rank",
157+
"desc",
158+
"describe",
159+
"distinct",
160+
"double",
161+
"drop",
162+
"dual",
163+
"else",
164+
"except",
165+
"exists",
166+
"explain",
167+
"false",
168+
"first_value",
169+
"float",
170+
"for",
171+
"force",
172+
"from",
173+
"full",
174+
"function",
175+
"grant",
176+
"group",
177+
"grouping",
178+
"grouping_id",
179+
"groups",
180+
"having",
181+
"hll",
182+
"host",
183+
"if",
184+
"ignore",
185+
"immediate",
186+
"in",
187+
"index",
188+
"infile",
189+
"inner",
190+
"insert",
191+
"int",
192+
"integer",
193+
"intersect",
194+
"into",
195+
"is",
196+
"join",
197+
"json",
198+
"key",
199+
"keys",
200+
"kill",
201+
"lag",
202+
"largeint",
203+
"last_value",
204+
"lateral",
205+
"lead",
206+
"left",
207+
"like",
208+
"limit",
209+
"load",
210+
"localtime",
211+
"localtimestamp",
212+
"maxvalue",
213+
"minus",
214+
"mod",
215+
"not",
216+
"ntile",
217+
"null",
218+
"on",
219+
"or",
220+
"order",
221+
"outer",
222+
"outfile",
223+
"over",
224+
"partition",
225+
"percentile",
226+
"primary",
227+
"procedure",
228+
"qualify",
229+
"range",
230+
"rank",
231+
"read",
232+
"regexp",
233+
"release",
234+
"rename",
235+
"replace",
236+
"revoke",
237+
"right",
238+
"rlike",
239+
"row",
240+
"row_number",
241+
"rows",
242+
"schema",
243+
"schemas",
244+
"select",
245+
"set",
246+
"set_var",
247+
"show",
248+
"smallint",
249+
"system",
250+
"table",
251+
"terminated",
252+
"text",
253+
"then",
254+
"tinyint",
255+
"to",
256+
"true",
257+
"union",
258+
"unique",
259+
"unsigned",
260+
"update",
261+
"use",
262+
"using",
263+
"values",
264+
"varchar",
265+
"when",
266+
"where",
267+
"with",
268+
}
269+
115270
def create_sql(self, expression: exp.Create) -> str:
116271
# Starrocks' primary key is defined outside of the schema, so we need to move it there
117272
schema = expression.this

tests/dialects/test_starrocks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def test_identity(self):
3939
self.validate_identity(
4040
"""SELECT CAST(PARSE_JSON(fieldvalue) -> '00000000-0000-0000-0000-00000000' AS VARCHAR) AS `code` FROM (SELECT '{"00000000-0000-0000-0000-00000000":"code01"}') AS t(fieldvalue)"""
4141
)
42+
self.validate_identity(
43+
"SELECT text FROM example_table", write_sql="SELECT `text` FROM example_table"
44+
)
4245

4346
def test_time(self):
4447
self.validate_identity("TIMESTAMP('2022-01-01')")

0 commit comments

Comments
 (0)