prettier-plugin-bq 0.2.61 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +26 -9
- package/dist/index.d.ts +51 -1
- package/dist/index.js +7 -14
- package/dist/index.js.map +1 -1
- package/dist/keywords.js +11 -14
- package/dist/keywords.js.map +1 -1
- package/dist/printer.d.ts +1 -0
- package/dist/printer.js +189 -94
- package/dist/printer.js.map +1 -1
- package/package.json +9 -20
package/dist/printer.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const prettier_1 = require("prettier");
|
|
6
|
-
const { builders: { breakParent, group, hardline, ifBreak, indent, join, line, lineSuffix, softline, }, } = prettier_1.doc;
|
|
7
|
-
const isNodeChild = (child) => {
|
|
1
|
+
import { reservedKeywords, globalFunctions, keysFunctions, aeadFunctions, hllCountFunctions, kllQuantilesFunctions, netFunctions, objFunctions, mlFunctions, aiFunctions, vectorIndexFunctions, } from "./keywords.js";
|
|
2
|
+
import { doc } from "prettier";
|
|
3
|
+
const { builders: { breakParent, group, hardline, ifBreak, indent, join, line, lineSuffix, softline, }, } = doc;
|
|
4
|
+
export const isNodeChild = (child) => {
|
|
8
5
|
if (child &&
|
|
9
6
|
typeof child === "object" &&
|
|
10
7
|
Object.keys(child).length === 1 &&
|
|
@@ -13,8 +10,7 @@ const isNodeChild = (child) => {
|
|
|
13
10
|
}
|
|
14
11
|
return false;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
const isNodeVecChild = (child) => {
|
|
13
|
+
export const isNodeVecChild = (child) => {
|
|
18
14
|
if (child &&
|
|
19
15
|
typeof child === "object" &&
|
|
20
16
|
Object.keys(child).length === 1 &&
|
|
@@ -23,7 +19,6 @@ const isNodeVecChild = (child) => {
|
|
|
23
19
|
}
|
|
24
20
|
return false;
|
|
25
21
|
};
|
|
26
|
-
exports.isNodeVecChild = isNodeVecChild;
|
|
27
22
|
class Printer {
|
|
28
23
|
constructor(path, options, print, node) {
|
|
29
24
|
this.path = path;
|
|
@@ -35,7 +30,7 @@ class Printer {
|
|
|
35
30
|
child(key, transform, consumeLeadingComments, sep) {
|
|
36
31
|
const child = this.children[key];
|
|
37
32
|
let f = (x) => x;
|
|
38
|
-
if (
|
|
33
|
+
if (isNodeChild(child)) {
|
|
39
34
|
if (typeof transform === "function") {
|
|
40
35
|
f = transform;
|
|
41
36
|
}
|
|
@@ -48,7 +43,7 @@ class Printer {
|
|
|
48
43
|
this.path.call((p) => p.call((p) => f(p.call(this.print, "Node")), key), "children"),
|
|
49
44
|
];
|
|
50
45
|
}
|
|
51
|
-
else if (
|
|
46
|
+
else if (isNodeVecChild(child)) {
|
|
52
47
|
if (typeof transform === "function") {
|
|
53
48
|
f = transform;
|
|
54
49
|
}
|
|
@@ -67,7 +62,7 @@ class Printer {
|
|
|
67
62
|
consumeAllCommentsOfX(key) {
|
|
68
63
|
let res = "";
|
|
69
64
|
const child = this.children[key];
|
|
70
|
-
if (
|
|
65
|
+
if (isNodeChild(child)) {
|
|
71
66
|
const leading_comments = child.Node.children.leading_comments;
|
|
72
67
|
if (leading_comments) {
|
|
73
68
|
res = leading_comments.NodeVec.map((x) => lineSuffix([" ", x.token.literal]));
|
|
@@ -112,10 +107,10 @@ class Printer {
|
|
|
112
107
|
else if (target === "all") {
|
|
113
108
|
const child = this.children[key];
|
|
114
109
|
let firstNodes = [];
|
|
115
|
-
if (
|
|
110
|
+
if (isNodeChild(child)) {
|
|
116
111
|
firstNodes = [getFirstNode(child.Node)];
|
|
117
112
|
}
|
|
118
|
-
else if (
|
|
113
|
+
else if (isNodeVecChild(child)) {
|
|
119
114
|
firstNodes = child.NodeVec.map((x) => getFirstNode(x));
|
|
120
115
|
}
|
|
121
116
|
const res = [];
|
|
@@ -142,10 +137,10 @@ class Printer {
|
|
|
142
137
|
getFirstNode(key) {
|
|
143
138
|
const child = this.children[key];
|
|
144
139
|
let firstNode;
|
|
145
|
-
if (
|
|
140
|
+
if (isNodeChild(child)) {
|
|
146
141
|
firstNode = getFirstNode(child.Node);
|
|
147
142
|
}
|
|
148
|
-
else if (
|
|
143
|
+
else if (isNodeVecChild(child) && child.NodeVec.length > 0) {
|
|
149
144
|
firstNode = getFirstNode(child.NodeVec[0]);
|
|
150
145
|
}
|
|
151
146
|
else {
|
|
@@ -178,7 +173,7 @@ class Printer {
|
|
|
178
173
|
}
|
|
179
174
|
len(key) {
|
|
180
175
|
const nodeVec = this.children[key];
|
|
181
|
-
if (
|
|
176
|
+
if (isNodeVecChild(nodeVec)) {
|
|
182
177
|
return nodeVec.NodeVec.length;
|
|
183
178
|
}
|
|
184
179
|
return 0;
|
|
@@ -204,10 +199,10 @@ class Printer {
|
|
|
204
199
|
if (upperOrLower === "upper") {
|
|
205
200
|
literal = literal.toUpperCase();
|
|
206
201
|
}
|
|
207
|
-
else if (!this.node.notGlobal && this.includedIn(
|
|
202
|
+
else if (!this.node.notGlobal && this.includedIn(reservedKeywords)) {
|
|
208
203
|
literal = literal.toUpperCase();
|
|
209
204
|
}
|
|
210
|
-
else if (this.options.
|
|
205
|
+
else if (this.options.printKeywordsInUpperCase &&
|
|
211
206
|
(literal.match(/^_PARTITION/i) ||
|
|
212
207
|
literal.match(/^_TABLE_/i) ||
|
|
213
208
|
literal.match(/^_FILE_/i) ||
|
|
@@ -231,7 +226,7 @@ class Printer {
|
|
|
231
226
|
}
|
|
232
227
|
setBreakRecommended(key) {
|
|
233
228
|
const child = this.children[key];
|
|
234
|
-
if (
|
|
229
|
+
if (isNodeChild(child)) {
|
|
235
230
|
child.Node.breakRecommended = true;
|
|
236
231
|
}
|
|
237
232
|
}
|
|
@@ -242,10 +237,10 @@ class Printer {
|
|
|
242
237
|
* e.g. when grouping a part of `this.child(key)`.
|
|
243
238
|
*/
|
|
244
239
|
const child = this.children[key];
|
|
245
|
-
if (
|
|
240
|
+
if (isNodeChild(child)) {
|
|
246
241
|
child.Node.groupRecommended = true;
|
|
247
242
|
}
|
|
248
|
-
else if (
|
|
243
|
+
else if (isNodeVecChild(child)) {
|
|
249
244
|
child.NodeVec.forEach((x) => {
|
|
250
245
|
x.groupRecommended = true;
|
|
251
246
|
});
|
|
@@ -253,7 +248,7 @@ class Printer {
|
|
|
253
248
|
}
|
|
254
249
|
setLiteral(key, literal) {
|
|
255
250
|
const child = this.children[key];
|
|
256
|
-
if (
|
|
251
|
+
if (isNodeChild(child)) {
|
|
257
252
|
const token = child.Node.token;
|
|
258
253
|
if (token) {
|
|
259
254
|
token.literal = literal;
|
|
@@ -262,10 +257,10 @@ class Printer {
|
|
|
262
257
|
}
|
|
263
258
|
setNotRoot(key) {
|
|
264
259
|
const child = this.children[key];
|
|
265
|
-
if (
|
|
260
|
+
if (isNodeChild(child)) {
|
|
266
261
|
child.Node.notRoot = true;
|
|
267
262
|
}
|
|
268
|
-
else if (
|
|
263
|
+
else if (isNodeVecChild(child)) {
|
|
269
264
|
child.NodeVec.forEach((x) => {
|
|
270
265
|
x.notRoot = true;
|
|
271
266
|
});
|
|
@@ -273,7 +268,7 @@ class Printer {
|
|
|
273
268
|
}
|
|
274
269
|
setNotGlobal(key) {
|
|
275
270
|
const child = this.children[key];
|
|
276
|
-
if (
|
|
271
|
+
if (isNodeChild(child)) {
|
|
277
272
|
child.Node.notGlobal = true;
|
|
278
273
|
}
|
|
279
274
|
}
|
|
@@ -281,7 +276,7 @@ class Printer {
|
|
|
281
276
|
if (this.hasLeadingComments(key))
|
|
282
277
|
return true;
|
|
283
278
|
const child = this.children[key];
|
|
284
|
-
if (!
|
|
279
|
+
if (!isNodeChild(child))
|
|
285
280
|
return false; // unnexpected pattern
|
|
286
281
|
const token = child.Node.token;
|
|
287
282
|
if (!token)
|
|
@@ -308,13 +303,13 @@ class Printer {
|
|
|
308
303
|
if (!this.options.printKeywordsInUpperCase) {
|
|
309
304
|
return;
|
|
310
305
|
}
|
|
311
|
-
if (
|
|
306
|
+
if (isNodeChild(child)) {
|
|
312
307
|
const token = child.Node.token;
|
|
313
308
|
if (token) {
|
|
314
309
|
token.literal = token.literal.toUpperCase();
|
|
315
310
|
}
|
|
316
311
|
}
|
|
317
|
-
else if (
|
|
312
|
+
else if (isNodeVecChild(child)) {
|
|
318
313
|
child.NodeVec.forEach((x) => {
|
|
319
314
|
const token = x.token;
|
|
320
315
|
if (token) {
|
|
@@ -331,10 +326,10 @@ const getFirstNode = (node, includeComment = false) => {
|
|
|
331
326
|
!includeComment) {
|
|
332
327
|
continue;
|
|
333
328
|
}
|
|
334
|
-
if (
|
|
329
|
+
if (isNodeChild(v)) {
|
|
335
330
|
candidates.push(getFirstNode(v.Node, includeComment));
|
|
336
331
|
}
|
|
337
|
-
else if (
|
|
332
|
+
else if (isNodeVecChild(v)) {
|
|
338
333
|
// NOTE maybe you don't have to check 2nd, 3rd, or latter node
|
|
339
334
|
v.NodeVec.forEach((x) => candidates.push(getFirstNode(x, includeComment)));
|
|
340
335
|
}
|
|
@@ -355,40 +350,57 @@ const getFirstNode = (node, includeComment = false) => {
|
|
|
355
350
|
}
|
|
356
351
|
return res;
|
|
357
352
|
};
|
|
358
|
-
const
|
|
353
|
+
const getLastNode = (node, includeComment = false) => {
|
|
354
|
+
const candidates = [];
|
|
355
|
+
for (const [k, v] of Object.entries(node.children)) {
|
|
356
|
+
if (["leading_comments", "trailing_comments"].includes(k) &&
|
|
357
|
+
!includeComment) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (isNodeChild(v)) {
|
|
361
|
+
candidates.push(getLastNode(v.Node, includeComment));
|
|
362
|
+
}
|
|
363
|
+
else if (isNodeVecChild(v)) {
|
|
364
|
+
// NOTE maybe you don't have to check 2nd, 3rd, or latter node
|
|
365
|
+
v.NodeVec.forEach((x) => candidates.push(getLastNode(x, includeComment)));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
let res = node;
|
|
369
|
+
for (const c of candidates) {
|
|
370
|
+
if (!c.token) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (!res.token) {
|
|
374
|
+
res = c;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (res.token.line < c.token.line ||
|
|
378
|
+
(c.token.line === res.token.line && res.token.column < c.token.column)) {
|
|
379
|
+
res = c;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return res;
|
|
383
|
+
};
|
|
384
|
+
export const printSQL = (path, options, print) => {
|
|
359
385
|
const node = path.node;
|
|
360
386
|
if (Array.isArray(node)) {
|
|
361
387
|
for (let i = 0; i < node.length - 1; i++) {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if (newLines) {
|
|
377
|
-
endLine += newLines.length;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
// start of statement
|
|
381
|
-
const startNode = getFirstNode(node[i + 1], true);
|
|
382
|
-
let startLine;
|
|
383
|
-
if (startNode.token) {
|
|
384
|
-
startLine = startNode.token.line;
|
|
385
|
-
}
|
|
386
|
-
else {
|
|
387
|
-
// EOF
|
|
388
|
-
startLine = endLine + 1;
|
|
389
|
-
}
|
|
390
|
-
node[i].emptyLines = startLine - endLine - 1; // >= -1
|
|
388
|
+
if ("semicolon" in node[i].children ||
|
|
389
|
+
node[i].node_type === "StandAloneExpr") {
|
|
390
|
+
const endNode = getLastNode(node[i], true);
|
|
391
|
+
if (!endNode.token)
|
|
392
|
+
continue;
|
|
393
|
+
const endLine = endNode.token.line;
|
|
394
|
+
const startNode = getFirstNode(node[i + 1], true);
|
|
395
|
+
let startLine;
|
|
396
|
+
if (startNode.token) {
|
|
397
|
+
startLine = startNode.token.line;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
// EOF
|
|
401
|
+
startLine = endLine + 1;
|
|
391
402
|
}
|
|
403
|
+
node[i].emptyLines = startLine - endLine - 1; // >= -1
|
|
392
404
|
}
|
|
393
405
|
}
|
|
394
406
|
return path.map(print);
|
|
@@ -632,6 +644,8 @@ const printSQL = (path, options, print) => {
|
|
|
632
644
|
return printSetStatement(path, options, print, node);
|
|
633
645
|
case "SingleTokenStatement":
|
|
634
646
|
return printSingleTokenStatement(path, options, print, node);
|
|
647
|
+
case "StandAloneExpr":
|
|
648
|
+
return printStandAloneExpr(path, options, print, node);
|
|
635
649
|
case "StringLiteral":
|
|
636
650
|
return printStringLiteral(path, options, print, node);
|
|
637
651
|
case "StructLiteral":
|
|
@@ -644,8 +658,14 @@ const printSQL = (path, options, print) => {
|
|
|
644
658
|
return printTableSamplePipeOperator(path, options, print, node);
|
|
645
659
|
case "TableSampleRatio":
|
|
646
660
|
return printTableSampleRatio(path, options, print, node);
|
|
647
|
-
case "
|
|
661
|
+
case "TemplateExpr":
|
|
648
662
|
return printIdentifier(path, options, print, node);
|
|
663
|
+
case "TemplateExprContinue":
|
|
664
|
+
return printTemplateExprContinue(path, options, print, node);
|
|
665
|
+
case "TemplateExprEnd":
|
|
666
|
+
return printTemplateExprEnd(path, options, print, node);
|
|
667
|
+
case "TemplateExprStart":
|
|
668
|
+
return printTemplateExprStart(path, options, print, node);
|
|
649
669
|
case "TransactionStatement":
|
|
650
670
|
return printTransactionStatement(path, options, print, node);
|
|
651
671
|
case "TrainingDataCustomHolidayClause":
|
|
@@ -698,7 +718,6 @@ const printSQL = (path, options, print) => {
|
|
|
698
718
|
throw new Error(`Not implemented node type: ${JSON.stringify(node)}`);
|
|
699
719
|
}
|
|
700
720
|
};
|
|
701
|
-
exports.printSQL = printSQL;
|
|
702
721
|
const printAccessOperator = (path, options, print, node) => {
|
|
703
722
|
const p = new Printer(path, options, print, node);
|
|
704
723
|
const docs = {
|
|
@@ -1531,7 +1550,7 @@ const printCallingFunctionGeneral = (path, options, print, node) => {
|
|
|
1531
1550
|
};
|
|
1532
1551
|
if (func.node_type === "Identifier") {
|
|
1533
1552
|
// SUBSTR("foo", 0, 2)
|
|
1534
|
-
if (
|
|
1553
|
+
if (globalFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1535
1554
|
func.isPreDefinedFunction = true;
|
|
1536
1555
|
}
|
|
1537
1556
|
}
|
|
@@ -1543,61 +1562,61 @@ const printCallingFunctionGeneral = (path, options, print, node) => {
|
|
|
1543
1562
|
// KEYS.NEW_KEYSET('AEAD_AES_GCM_256')
|
|
1544
1563
|
switch (parent.token.literal.toUpperCase()) {
|
|
1545
1564
|
case "SAFE":
|
|
1546
|
-
if (
|
|
1565
|
+
if (globalFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1547
1566
|
func.isPreDefinedFunction = true;
|
|
1548
1567
|
toUpper(parent.token);
|
|
1549
1568
|
}
|
|
1550
1569
|
break;
|
|
1551
1570
|
case "KEYS":
|
|
1552
|
-
if (
|
|
1571
|
+
if (keysFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1553
1572
|
func.isPreDefinedFunction = true;
|
|
1554
1573
|
toUpper(parent.token);
|
|
1555
1574
|
}
|
|
1556
1575
|
break;
|
|
1557
1576
|
case "AEAD":
|
|
1558
|
-
if (
|
|
1577
|
+
if (aeadFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1559
1578
|
func.isPreDefinedFunction = true;
|
|
1560
1579
|
toUpper(parent.token);
|
|
1561
1580
|
}
|
|
1562
1581
|
break;
|
|
1563
1582
|
case "NET":
|
|
1564
|
-
if (
|
|
1583
|
+
if (netFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1565
1584
|
func.isPreDefinedFunction = true;
|
|
1566
1585
|
toUpper(parent.token);
|
|
1567
1586
|
}
|
|
1568
1587
|
break;
|
|
1569
1588
|
case "HLL_COUNT":
|
|
1570
|
-
if (
|
|
1589
|
+
if (hllCountFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1571
1590
|
func.isPreDefinedFunction = true;
|
|
1572
1591
|
toUpper(parent.token);
|
|
1573
1592
|
}
|
|
1574
1593
|
break;
|
|
1575
1594
|
case "KLL_QUANTILES":
|
|
1576
|
-
if (
|
|
1595
|
+
if (kllQuantilesFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1577
1596
|
func.isPreDefinedFunction = true;
|
|
1578
1597
|
toUpper(parent.token);
|
|
1579
1598
|
}
|
|
1580
1599
|
break;
|
|
1581
1600
|
case "OBJ":
|
|
1582
|
-
if (
|
|
1601
|
+
if (objFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1583
1602
|
func.isPreDefinedFunction = true;
|
|
1584
1603
|
toUpper(parent.token);
|
|
1585
1604
|
}
|
|
1586
1605
|
break;
|
|
1587
1606
|
case "ML":
|
|
1588
|
-
if (
|
|
1607
|
+
if (mlFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1589
1608
|
func.isPreDefinedFunction = true;
|
|
1590
1609
|
toUpper(parent.token);
|
|
1591
1610
|
}
|
|
1592
1611
|
break;
|
|
1593
1612
|
case "AI":
|
|
1594
|
-
if (
|
|
1613
|
+
if (aiFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1595
1614
|
func.isPreDefinedFunction = true;
|
|
1596
1615
|
toUpper(parent.token);
|
|
1597
1616
|
}
|
|
1598
1617
|
break;
|
|
1599
1618
|
case "VECTOR_INDEX":
|
|
1600
|
-
if (
|
|
1619
|
+
if (vectorIndexFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1601
1620
|
func.isPreDefinedFunction = true;
|
|
1602
1621
|
toUpper(parent.token);
|
|
1603
1622
|
}
|
|
@@ -1611,63 +1630,63 @@ const printCallingFunctionGeneral = (path, options, print, node) => {
|
|
|
1611
1630
|
if (grandParent.token.literal.toUpperCase() === "SAFE") {
|
|
1612
1631
|
switch (parent.token.literal.toUpperCase()) {
|
|
1613
1632
|
case "KEYS":
|
|
1614
|
-
if (
|
|
1633
|
+
if (keysFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1615
1634
|
func.isPreDefinedFunction = true;
|
|
1616
1635
|
toUpper(parent.token);
|
|
1617
1636
|
toUpper(grandParent.token);
|
|
1618
1637
|
}
|
|
1619
1638
|
break;
|
|
1620
1639
|
case "AEAD":
|
|
1621
|
-
if (
|
|
1640
|
+
if (aeadFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1622
1641
|
func.isPreDefinedFunction = true;
|
|
1623
1642
|
toUpper(parent.token);
|
|
1624
1643
|
toUpper(grandParent.token);
|
|
1625
1644
|
}
|
|
1626
1645
|
break;
|
|
1627
1646
|
case "NET":
|
|
1628
|
-
if (
|
|
1647
|
+
if (netFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1629
1648
|
func.isPreDefinedFunction = true;
|
|
1630
1649
|
toUpper(parent.token);
|
|
1631
1650
|
toUpper(grandParent.token);
|
|
1632
1651
|
}
|
|
1633
1652
|
break;
|
|
1634
1653
|
case "HLL_COUNT":
|
|
1635
|
-
if (
|
|
1654
|
+
if (hllCountFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1636
1655
|
func.isPreDefinedFunction = true;
|
|
1637
1656
|
toUpper(parent.token);
|
|
1638
1657
|
toUpper(grandParent.token);
|
|
1639
1658
|
}
|
|
1640
1659
|
break;
|
|
1641
1660
|
case "KLL_QUANTILES":
|
|
1642
|
-
if (
|
|
1661
|
+
if (kllQuantilesFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1643
1662
|
func.isPreDefinedFunction = true;
|
|
1644
1663
|
toUpper(parent.token);
|
|
1645
1664
|
toUpper(grandParent.token);
|
|
1646
1665
|
}
|
|
1647
1666
|
break;
|
|
1648
1667
|
case "OBJ":
|
|
1649
|
-
if (
|
|
1668
|
+
if (objFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1650
1669
|
func.isPreDefinedFunction = true;
|
|
1651
1670
|
toUpper(parent.token);
|
|
1652
1671
|
toUpper(grandParent.token);
|
|
1653
1672
|
}
|
|
1654
1673
|
break;
|
|
1655
1674
|
case "ML":
|
|
1656
|
-
if (
|
|
1675
|
+
if (mlFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1657
1676
|
func.isPreDefinedFunction = true;
|
|
1658
1677
|
toUpper(parent.token);
|
|
1659
1678
|
toUpper(grandParent.token);
|
|
1660
1679
|
}
|
|
1661
1680
|
break;
|
|
1662
1681
|
case "AI":
|
|
1663
|
-
if (
|
|
1682
|
+
if (aiFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1664
1683
|
func.isPreDefinedFunction = true;
|
|
1665
1684
|
toUpper(parent.token);
|
|
1666
1685
|
toUpper(grandParent.token);
|
|
1667
1686
|
}
|
|
1668
1687
|
break;
|
|
1669
1688
|
case "VECTOR_INDEX":
|
|
1670
|
-
if (
|
|
1689
|
+
if (vectorIndexFunctions.includes(func.token.literal.toUpperCase())) {
|
|
1671
1690
|
func.isPreDefinedFunction = true;
|
|
1672
1691
|
toUpper(parent.token);
|
|
1673
1692
|
toUpper(grandParent.token);
|
|
@@ -1684,13 +1703,11 @@ const printCallingFunctionGeneral = (path, options, print, node) => {
|
|
|
1684
1703
|
// NORMALIZE
|
|
1685
1704
|
if (["NORMALIZE", "NORMALIZE_AND_CASEFOLD"].includes(func_literal) &&
|
|
1686
1705
|
2 <= p.len("args")) {
|
|
1687
|
-
toUpper(args.NodeVec[1].token);
|
|
1706
|
+
toUpper(args.NodeVec[node.isChained ? 0 : 1].token);
|
|
1688
1707
|
}
|
|
1689
1708
|
// XXX_DIFF
|
|
1690
1709
|
if (["DATE_DIFF", "DATETIME_DIFF", "TIME_DIFF", "TIMESTAMP_DIFF"].includes(func_literal)) {
|
|
1691
|
-
|
|
1692
|
-
if (node)
|
|
1693
|
-
node.isDatePart = true; // not chained function
|
|
1710
|
+
args.NodeVec[node.isChained ? 1 : 2].isDatePart = true;
|
|
1694
1711
|
}
|
|
1695
1712
|
// XXX_TRUNC
|
|
1696
1713
|
if ([
|
|
@@ -1699,15 +1716,11 @@ const printCallingFunctionGeneral = (path, options, print, node) => {
|
|
|
1699
1716
|
"TIME_TRUNC",
|
|
1700
1717
|
"TIMESTAMP_TRUNC",
|
|
1701
1718
|
].includes(func_literal)) {
|
|
1702
|
-
|
|
1703
|
-
if (node)
|
|
1704
|
-
node.isDatePart = true; // not chained function
|
|
1719
|
+
args.NodeVec[node.isChained ? 0 : 1].isDatePart = true;
|
|
1705
1720
|
}
|
|
1706
1721
|
// LAST_DAY
|
|
1707
1722
|
if (func_literal === "LAST_DAY" && 2 <= p.len("args")) {
|
|
1708
|
-
|
|
1709
|
-
if (node)
|
|
1710
|
-
node.isDatePart = true; // not chained function
|
|
1723
|
+
args.NodeVec[node.isChained ? 0 : 1].isDatePart = true;
|
|
1711
1724
|
}
|
|
1712
1725
|
}
|
|
1713
1726
|
}
|
|
@@ -2965,6 +2978,7 @@ const printFromStatement = (path, options, print, node) => {
|
|
|
2965
2978
|
};
|
|
2966
2979
|
const printFunctionChain = (path, options, print, node) => {
|
|
2967
2980
|
const p = new Printer(path, options, print, node);
|
|
2981
|
+
node.children.right.Node.isChained = true;
|
|
2968
2982
|
const docs = {
|
|
2969
2983
|
left: p.child("left"),
|
|
2970
2984
|
leading_comments: printLeadingComments(path, options, print, node),
|
|
@@ -4530,6 +4544,14 @@ const printSingleTokenStatement = (path, options, print, node) => {
|
|
|
4530
4544
|
p.newLine(),
|
|
4531
4545
|
];
|
|
4532
4546
|
};
|
|
4547
|
+
const printStandAloneExpr = (path, options, print, node) => {
|
|
4548
|
+
const p = new Printer(path, options, print, node);
|
|
4549
|
+
const docs = {
|
|
4550
|
+
self: "", // eslint-disable-line unicorn/no-unused-properties
|
|
4551
|
+
expr: p.child("expr"),
|
|
4552
|
+
};
|
|
4553
|
+
return [docs.expr, p.newLine()];
|
|
4554
|
+
};
|
|
4533
4555
|
const printStringLiteral = (path, options, print, node) => {
|
|
4534
4556
|
const p = new Printer(path, options, print, node);
|
|
4535
4557
|
const docs = {
|
|
@@ -4654,6 +4676,79 @@ const printTableSampleRatio = (path, options, print, node) => {
|
|
|
4654
4676
|
docs.rparen,
|
|
4655
4677
|
];
|
|
4656
4678
|
};
|
|
4679
|
+
const printTemplateExprContinue = (path, options, print, node) => {
|
|
4680
|
+
const p = new Printer(path, options, print, node);
|
|
4681
|
+
p.setNotRoot("exprs");
|
|
4682
|
+
p.setGroupRecommended("exprs");
|
|
4683
|
+
const docs = {
|
|
4684
|
+
leading_comments: printLeadingComments(path, options, print, node),
|
|
4685
|
+
self: p.self("asItIs"),
|
|
4686
|
+
trailing_comments: printTrailingComments(path, options, print, node),
|
|
4687
|
+
exprs: p.child("exprs", (x) => [line, x]),
|
|
4688
|
+
};
|
|
4689
|
+
return [
|
|
4690
|
+
docs.leading_comments,
|
|
4691
|
+
docs.self,
|
|
4692
|
+
docs.trailing_comments,
|
|
4693
|
+
indent(docs.exprs),
|
|
4694
|
+
];
|
|
4695
|
+
};
|
|
4696
|
+
const printTemplateExprEnd = (path, options, print, node) => {
|
|
4697
|
+
const p = new Printer(path, options, print, node);
|
|
4698
|
+
const docs = {
|
|
4699
|
+
leading_comments: printLeadingComments(path, options, print, node),
|
|
4700
|
+
self: p.self("asItIs"),
|
|
4701
|
+
trailing_comments: printTrailingComments(path, options, print, node),
|
|
4702
|
+
};
|
|
4703
|
+
return [docs.leading_comments, docs.self, docs.trailing_comments];
|
|
4704
|
+
};
|
|
4705
|
+
const printTemplateExprStart = (path, options, print, node) => {
|
|
4706
|
+
const p = new Printer(path, options, print, node);
|
|
4707
|
+
p.setNotRoot("exprs");
|
|
4708
|
+
p.setGroupRecommended("exprs");
|
|
4709
|
+
const docs = {
|
|
4710
|
+
leading_comments: printLeadingComments(path, options, print, node),
|
|
4711
|
+
self: p.self("asItIs"),
|
|
4712
|
+
trailing_comments: printTrailingComments(path, options, print, node),
|
|
4713
|
+
exprs: p.child("exprs", (x) => [line, x]),
|
|
4714
|
+
continues: p.child("continues", (x) => [line, x]),
|
|
4715
|
+
end: p.child("end"),
|
|
4716
|
+
as: "", // eslint-disable-line unicorn/no-unused-properties
|
|
4717
|
+
alias: printAlias(path, options, print, node),
|
|
4718
|
+
order: printOrder(path, options, print, node),
|
|
4719
|
+
null_order: "", // eslint-disable-line unicorn/no-unused-properties
|
|
4720
|
+
// do not use printComma here
|
|
4721
|
+
// additional trailing comma may break your code
|
|
4722
|
+
comma: p.child("comma", undefined, "all"),
|
|
4723
|
+
with_offset: p.child("with_offset", undefined, "all"),
|
|
4724
|
+
pivot: printPivotOrUnpivotOperator(path, options, print, node),
|
|
4725
|
+
unpivot: "", // eslint-disable-line unicorn/no-unused-properties
|
|
4726
|
+
match_recognize: p.child("match_recognize", undefined, "all"),
|
|
4727
|
+
};
|
|
4728
|
+
return [
|
|
4729
|
+
docs.leading_comments,
|
|
4730
|
+
group([
|
|
4731
|
+
docs.self,
|
|
4732
|
+
indent(docs.exprs),
|
|
4733
|
+
docs.continues,
|
|
4734
|
+
0 < p.children.exprs.NodeVec.length ||
|
|
4735
|
+
0 < p.children.continues.NodeVec.length
|
|
4736
|
+
? line
|
|
4737
|
+
: "",
|
|
4738
|
+
docs.end,
|
|
4739
|
+
docs.trailing_comments,
|
|
4740
|
+
docs.alias,
|
|
4741
|
+
docs.order,
|
|
4742
|
+
docs.pivot,
|
|
4743
|
+
docs.comma,
|
|
4744
|
+
p.has("match_recognize") ? " " : "",
|
|
4745
|
+
docs.match_recognize,
|
|
4746
|
+
p.has("with_offset") ? " " : "",
|
|
4747
|
+
docs.with_offset,
|
|
4748
|
+
]),
|
|
4749
|
+
p.newLine(),
|
|
4750
|
+
];
|
|
4751
|
+
};
|
|
4657
4752
|
const printTransactionStatement = (path, options, print, node) => {
|
|
4658
4753
|
const p = new Printer(path, options, print, node);
|
|
4659
4754
|
const docs = {
|