Skip to content

Commit c4bef88

Browse files
committed
Reduce intersection between functions and keywords
1 parent ae7ee87 commit c4bef88

File tree

4 files changed

+20
-41
lines changed

4 files changed

+20
-41
lines changed

src/languages/clickhouse/clickhouse.formatter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ const reservedSetOperations = expandPhrases([
226226
const reservedJoins = expandPhrases([
227227
// https://clickhouse.com/docs/sql-reference/statements/select/join
228228
'[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ALL|ASOF] JOIN',
229+
// https://clickhouse.com/docs/sql-reference/statements/select/array-join
230+
'[LEFT] ARRAY JOIN',
229231
]);
230232

231233
const reservedKeywordPhrases = expandPhrases([

src/languages/clickhouse/clickhouse.functions.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export const functions: string[] = [
1313
'CRC32',
1414
'CRC32IEEE',
1515
'CRC64',
16-
'DATABASE',
1716
'DATE',
1817
'DATE_DIFF',
1918
'DATE_FORMAT',
@@ -189,7 +188,6 @@ export const functions: string[] = [
189188
'aggThrow',
190189
'alphaTokens',
191190
'analysisOfVariance',
192-
'and',
193191
'anova',
194192
'any',
195193
'anyHeavy',
@@ -603,7 +601,9 @@ export const functions: string[] = [
603601
'flatten',
604602
'flattenTuple',
605603
'floor',
606-
'format',
604+
// We do not include FORMAT as a function, because it's also a keyword.
605+
// FORMAT clauses are fairly common: https://clickhouse.com/docs/sql-reference/statements/select/format
606+
// 'format',
607607
'formatDateTime',
608608
'formatDateTimeInJodaSyntax',
609609
'formatQuery',
@@ -766,7 +766,8 @@ export const functions: string[] = [
766766
'ifNotFinite',
767767
'ifNull',
768768
'ignore',
769-
'ilike',
769+
// ilike() is a function, but the ILIKE keyword is very common in SQL.
770+
// 'ilike',
770771
'inIgnoreSet',
771772
'indexHint',
772773
'indexOf',
@@ -843,7 +844,8 @@ export const functions: string[] = [
843844
'levenshteinDistance',
844845
'levenshteinDistanceUTF8',
845846
'lgamma',
846-
'like',
847+
// like() is a function, but the ILIKE keyword is very common in SQL.
848+
// 'like',
847849
'ln',
848850
'locate',
849851
'log',
@@ -1005,7 +1007,8 @@ export const functions: string[] = [
10051007
'normalizeUTF8NFKD',
10061008
'normalizedQueryHash',
10071009
'normalizedQueryHashKeepNames',
1008-
'not',
1010+
// not() is a function, but the NOT keyword is very common in SQL.
1011+
// 'not',
10091012
'notEmpty',
10101013
'notEquals',
10111014
'notILike',
@@ -1043,7 +1046,6 @@ export const functions: string[] = [
10431046
'numericIndexedVectorPointwiseSubtract',
10441047
'numericIndexedVectorShortDebugString',
10451048
'numericIndexedVectorToMap',
1046-
'or',
10471049
'overlay',
10481050
'overlayUTF8',
10491051
'parseDateTime',
@@ -1185,7 +1187,8 @@ export const functions: string[] = [
11851187
'randomPrintableASCII',
11861188
'randomString',
11871189
'randomStringUTF8',
1188-
'range',
1190+
// range() is a function, but the RANGE keyword is important for window functions.
1191+
// 'range',
11891192
'rank',
11901193
'rankCorr',
11911194
'readWKBLineString',
@@ -1283,7 +1286,6 @@ export const functions: string[] = [
12831286
'serverTimeZone',
12841287
'serverTimezone',
12851288
'serverUUID',
1286-
'set',
12871289
'shardCount',
12881290
'shardNum',
12891291
'showCertificate',
@@ -1629,7 +1631,8 @@ export const functions: string[] = [
16291631
'trimLeft',
16301632
'trimRight',
16311633
'trunc',
1632-
'truncate',
1634+
// truncate() is a function, but the TRUNCATE keyword is a statement type.
1635+
// 'truncate',
16331636
'tryBase32Decode',
16341637
'tryBase58Decode',
16351638
'tryBase64Decode',
@@ -1744,7 +1747,8 @@ export const functions: string[] = [
17441747
'PostgreSQL',
17451748
'MySQL',
17461749
'SQLite',
1747-
'Backup',
1750+
// Disabling this because it's more likely to be used in a GRANT statement as a permission.
1751+
// 'Backup',
17481752
'MaterializedPostgreSQL',
17491753
'DataLakeCatalog',
17501754
];

src/languages/clickhouse/clickhouse.keywords.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const keywords: string[] = [
1414
'ANTI',
1515
'APPEND',
1616
'APPLY',
17-
'ARRAY',
1817
'AS',
1918
'ASC',
2019
'ASCENDING',
@@ -39,11 +38,9 @@ export const keywords: string[] = [
3938
'CACHES',
4039
'CASCADE',
4140
'CASE',
42-
'CAST',
4341
'CHANGE',
4442
'CHANGEABLE_IN_READONLY',
4543
'CHANGED',
46-
'CHAR',
4744
'CHARACTER',
4845
'CHECK',
4946
'CLEANUP',
@@ -66,14 +63,10 @@ export const keywords: string[] = [
6663
'CROSS',
6764
'CUBE',
6865
'CURRENT',
69-
'CURRENTUSER',
70-
'CURRENT_USER',
7166
'D',
7267
'DATA',
7368
'DATABASE',
7469
'DATABASES',
75-
'DATE',
76-
'DAY',
7770
'DAYS',
7871
'DD',
7972
'DDL',
@@ -98,7 +91,6 @@ export const keywords: string[] = [
9891
'DOUBLE_SHA1_PASSWORD',
9992
'DROP',
10093
'ELSE',
101-
'EMPTY',
10294
'ENABLED',
10395
'END',
10496
'ENFORCED',
@@ -120,7 +112,6 @@ export const keywords: string[] = [
120112
'FALSE',
121113
'FETCH',
122114
'FIELDS',
123-
'FILE',
124115
'FILESYSTEM',
125116
'FILL',
126117
'FILTER',
@@ -151,15 +142,12 @@ export const keywords: string[] = [
151142
'HH',
152143
'HIERARCHICAL',
153144
'HOST',
154-
'HOUR',
155145
'HOURS',
156146
'HTTP',
157147
// Disabling this because it's a keyword, but formats far more than
158148
// it should.
159149
// 'ID',
160150
'IDENTIFIED',
161-
'IF',
162-
'IGNORE',
163151
'ILIKE',
164152
'IN',
165153
'INDEX',
@@ -192,8 +180,6 @@ export const keywords: string[] = [
192180
'LAYOUT',
193181
'LDAP',
194182
'LEADING',
195-
'LEFT',
196-
'LESS',
197183
'LEVEL',
198184
'LIFETIME',
199185
'LIGHTWEIGHT',
@@ -206,26 +192,18 @@ export const keywords: string[] = [
206192
'LOCAL',
207193
'M',
208194
'MASK',
209-
'MATCH',
210-
'MATERIALIZE',
211195
'MATERIALIZED',
212-
'MAX',
213196
'MCS',
214197
'MEMORY',
215198
'MERGES',
216199
'METRICS',
217200
'MI',
218201
'MICROSECOND',
219202
'MICROSECONDS',
220-
'MILLISECOND',
221203
'MILLISECONDS',
222-
'MIN',
223-
'MINUTE',
224204
'MINUTES',
225205
'MM',
226-
'MOD',
227206
'MODIFY',
228-
'MONTH',
229207
'MONTHS',
230208
'MOVE',
231209
'MS',
@@ -284,7 +262,6 @@ export const keywords: string[] = [
284262
'Q',
285263
'QQ',
286264
'QUALIFY',
287-
'QUARTER',
288265
'QUARTERS',
289266
'QUERY',
290267
'QUOTA',
@@ -300,15 +277,13 @@ export const keywords: string[] = [
300277
'REGEXP',
301278
'REMOVE',
302279
'RENAME',
303-
'REPLACE',
304280
'RESET',
305281
'RESPECT',
306282
'RESTORE',
307283
'RESTRICT',
308284
'RESTRICTIVE',
309285
'RESUME',
310286
'REVOKE',
311-
'RIGHT',
312287
'ROLE',
313288
'ROLES',
314289
'ROLLBACK',
@@ -321,7 +296,6 @@ export const keywords: string[] = [
321296
'SAMPLE',
322297
'SAN',
323298
'SCHEME',
324-
'SECOND',
325299
'SECONDS',
326300
'SECURITY',
327301
'SELECT',
@@ -379,7 +353,6 @@ export const keywords: string[] = [
379353
'THEN',
380354
'TIES',
381355
'TIME',
382-
'TIMESTAMP',
383356
'TO',
384357
'TOP',
385358
'TOTALS',
@@ -404,7 +377,6 @@ export const keywords: string[] = [
404377
'UPDATE',
405378
'URL',
406379
'USE',
407-
'USER',
408380
'USING',
409381
'UUID',
410382
'VALID',
@@ -415,7 +387,6 @@ export const keywords: string[] = [
415387
'VOLUME',
416388
'WATCH',
417389
'WATERMARK',
418-
'WEEK',
419390
'WEEKS',
420391
'WHEN',
421392
'WHERE',
@@ -425,7 +396,6 @@ export const keywords: string[] = [
425396
'WK',
426397
'WRITABLE',
427398
'WW',
428-
'YEAR',
429399
'YEARS',
430400
'YY',
431401
'YYYY',

test/clickhouse.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ describe('ClickhouseFormatter', () => {
157157
'ANY JOIN',
158158
'ALL JOIN',
159159
'ASOF JOIN',
160+
161+
'ARRAY JOIN',
162+
'LEFT ARRAY JOIN',
160163
],
161164
});
162165
supportsSetOperations(format, ['UNION', 'UNION ALL', 'UNION DISTINCT', 'PARALLEL WITH']);

0 commit comments

Comments
 (0)