Skip to content

Commit 79ff3af

Browse files
authored
Merge PR #417: Fix crash caused by ROWS BETWEEN
2 parents adddedc + 4f545c8 commit 79ff3af

18 files changed

+112
-15
lines changed

src/languages/bigquery/bigquery.formatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ const reservedJoins = expandPhrases([
127127
'{INNER | CROSS} JOIN',
128128
]);
129129

130-
const reservedPhrases = [
130+
const reservedPhrases = expandPhrases([
131131
// https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#tablesample_operator
132132
'TABLESAMPLE SYSTEM',
133133
// From DDL: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
134134
'ANY TYPE',
135135
'ALL COLUMNS',
136136
'NOT DETERMINISTIC',
137-
];
137+
// inside window definitions
138+
'{ROWS | RANGE} BETWEEN',
139+
]);
138140

139141
// https://cloud.google.com/bigquery/docs/reference/#standard-sql-reference
140142
export default class BigQueryFormatter extends Formatter {

src/languages/db2/db2.formatter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const reservedCommands = expandPhrases([
1313
'WHERE',
1414
'GROUP BY',
1515
'HAVING',
16+
'PARTITION BY',
1617
'ORDER BY [INPUT SEQUENCE]',
1718
'FETCH FIRST',
1819
// Data modification
@@ -165,7 +166,7 @@ const reservedJoins = expandPhrases([
165166
'{INNER | CROSS} JOIN',
166167
]);
167168

168-
const reservedPhrases = ['ON DELETE', 'ON UPDATE'];
169+
const reservedPhrases = expandPhrases(['ON DELETE', 'ON UPDATE', '{ROWS | RANGE} BETWEEN']);
169170

170171
// https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/db2/rbafzintro.htm
171172
export default class Db2Formatter extends Formatter {

src/languages/db2/db2.functions.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,20 @@ export const functions = flatKeywordList({
302302
// https://www.ibm.com/docs/en/db2-for-zos/11?topic=functions-row
303303
row: ['UNPACK'],
304304
// https://www.ibm.com/docs/en/db2-for-zos/12?topic=expressions-olap-specification
305-
olap: ['FIRST_VALUE', 'LAG', 'LAST_VALUE', 'LEAD', 'NTH_VALUE', 'NTILE', 'RATIO_TO_REPORT'],
305+
olap: [
306+
'CUME_DIST',
307+
'PERCENT_RANK',
308+
'RANK',
309+
'DENSE_RANK',
310+
'NTILE',
311+
'LAG',
312+
'LEAD',
313+
'ROW_NUMBER',
314+
'FIRST_VALUE',
315+
'LAST_VALUE',
316+
'NTH_VALUE',
317+
'RATIO_TO_REPORT',
318+
],
306319
// Type casting
307320
cast: ['CAST'],
308321
});

src/languages/hive/hive.formatter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const reservedJoins = expandPhrases([
7878
'LEFT SEMI JOIN',
7979
]);
8080

81+
const reservedPhrases = expandPhrases(['{ROWS | RANGE} BETWEEN']);
82+
8183
// https://cwiki.apache.org/confluence/display/Hive/LanguageManual
8284
export default class HiveFormatter extends Formatter {
8385
static operators = ['<=>', '==', '||'];
@@ -89,6 +91,7 @@ export default class HiveFormatter extends Formatter {
8991
reservedSetOperations,
9092
reservedJoins,
9193
reservedDependentClauses: ['WHEN', 'ELSE'],
94+
reservedPhrases,
9295
reservedKeywords: keywords,
9396
reservedFunctionNames: functions,
9497
extraParens: ['[]'],

src/languages/mariadb/mariadb.formatter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const reservedCommands = expandPhrases([
1414
'WHERE',
1515
'GROUP BY',
1616
'HAVING',
17+
'PARTITION BY',
1718
'ORDER BY',
1819
'LIMIT',
1920
'OFFSET',
@@ -252,7 +253,12 @@ const reservedJoins = expandPhrases([
252253
'STRAIGHT_JOIN',
253254
]);
254255

255-
const reservedPhrases = ['ON DELETE', 'ON UPDATE', 'CHARACTER SET'];
256+
const reservedPhrases = expandPhrases([
257+
'ON DELETE',
258+
'ON UPDATE',
259+
'CHARACTER SET',
260+
'{ROWS | RANGE} BETWEEN',
261+
]);
256262

257263
// For reference: https://mariadb.com/kb/en/sql-statements-structure/
258264
export default class MariaDbFormatter extends Formatter {

src/languages/mysql/mysql.formatter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ const reservedJoins = expandPhrases([
221221
'STRAIGHT_JOIN',
222222
]);
223223

224-
const reservedPhrases = ['ON DELETE', 'ON UPDATE', 'CHARACTER SET'];
224+
const reservedPhrases = expandPhrases([
225+
'ON DELETE',
226+
'ON UPDATE',
227+
'CHARACTER SET',
228+
'{ROWS | RANGE} BETWEEN',
229+
]);
225230

226231
// https://dev.mysql.com/doc/refman/8.0/en/
227232
export default class MySqlFormatter extends Formatter {

src/languages/n1ql/n1ql.formatter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const reservedSetOperations = expandPhrases(['UNION [ALL]', 'EXCEPT [ALL]', 'INT
7575

7676
const reservedJoins = expandPhrases(['JOIN', '{LEFT | RIGHT} [OUTER] JOIN', 'INNER JOIN']);
7777

78+
const reservedPhrases = expandPhrases(['{ROWS | RANGE | GROUPS} BETWEEN']);
79+
7880
// For reference: http://docs.couchbase.com.s3-website-us-west-1.amazonaws.com/server/6.0/n1ql/n1ql-language-reference/index.html
7981
export default class N1qlFormatter extends Formatter {
8082
static operators = ['==', '||'];
@@ -86,6 +88,7 @@ export default class N1qlFormatter extends Formatter {
8688
reservedSetOperations,
8789
reservedJoins,
8890
reservedDependentClauses: ['WHEN', 'ELSE'],
91+
reservedPhrases,
8992
supportsXor: true,
9093
reservedKeywords: keywords,
9194
reservedFunctionNames: functions,

src/languages/plsql/plsql.formatter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const reservedCommands = expandPhrases([
1414
'WHERE',
1515
'GROUP BY',
1616
'HAVING',
17+
'PARTITION BY',
1718
'ORDER [SIBLINGS] BY',
1819
'OFFSET',
1920
'FETCH {FIRST | NEXT}',
@@ -69,7 +70,12 @@ const reservedJoins = expandPhrases([
6970
'{CROSS | OUTER} APPLY',
7071
]);
7172

72-
const reservedPhrases = ['ON DELETE', 'ON UPDATE', 'ON COMMIT'];
73+
const reservedPhrases = expandPhrases([
74+
'ON DELETE',
75+
'ON UPDATE',
76+
'ON COMMIT',
77+
'{ROWS | RANGE} BETWEEN',
78+
]);
7379

7480
export default class PlSqlFormatter extends Formatter {
7581
static operators = [

src/languages/postgresql/postgresql.formatter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ const reservedJoins = expandPhrases([
237237
'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN',
238238
]);
239239

240-
const reservedPhrases = ['ON DELETE', 'ON UPDATE'];
240+
const reservedPhrases = expandPhrases([
241+
'ON DELETE',
242+
'ON UPDATE',
243+
'{ROWS | RANGE | GROUPS} BETWEEN',
244+
]);
241245

242246
const binaryOperators = [
243247
// Math Operators

src/languages/redshift/redshift.formatter.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const reservedCommands = expandPhrases([
1313
'WHERE',
1414
'GROUP BY',
1515
'HAVING',
16+
'PARTITION BY',
1617
'ORDER BY',
1718
'LIMIT',
1819
'OFFSET',
@@ -127,13 +128,15 @@ const reservedJoins = expandPhrases([
127128
'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN',
128129
]);
129130

130-
const reservedPhrases = [
131+
const reservedPhrases = expandPhrases([
131132
// https://docs.aws.amazon.com/redshift/latest/dg/copy-parameters-data-conversion.html
132133
'NULL AS',
133134
// https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_EXTERNAL_SCHEMA.html
134135
'DATA CATALOG',
135136
'HIVE METASTORE',
136-
];
137+
// in window specifications
138+
'{ROWS | RANGE} BETWEEN',
139+
]);
137140

138141
// https://docs.aws.amazon.com/redshift/latest/dg/cm_chap_SQLCommandRef.html
139142
export default class RedshiftFormatter extends Formatter {

0 commit comments

Comments
 (0)