prettier-plugin-bq 0.2.39

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.
@@ -0,0 +1,4190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.printSQL = exports.isNodeVecChild = exports.isNodeChild = void 0;
4
+ const keywords_1 = require("./keywords");
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) => {
8
+ if (child &&
9
+ typeof child === "object" &&
10
+ Object.keys(child).length === 1 &&
11
+ "Node" in child) {
12
+ return true;
13
+ }
14
+ return false;
15
+ };
16
+ exports.isNodeChild = isNodeChild;
17
+ const isNodeVecChild = (child) => {
18
+ if (child &&
19
+ typeof child === "object" &&
20
+ Object.keys(child).length === 1 &&
21
+ "NodeVec" in child) {
22
+ return true;
23
+ }
24
+ return false;
25
+ };
26
+ exports.isNodeVecChild = isNodeVecChild;
27
+ class Printer {
28
+ constructor(path, options, print, node) {
29
+ this.path = path;
30
+ this.options = options;
31
+ this.print = print;
32
+ this.node = node;
33
+ this.children = this.node.children;
34
+ }
35
+ child(key, transform, consumeLeadingComments, sep) {
36
+ const child = this.children[key];
37
+ let f = (x) => x;
38
+ if (exports.isNodeChild(child)) {
39
+ if (typeof transform === "function") {
40
+ f = transform;
41
+ }
42
+ let comments = "";
43
+ if (consumeLeadingComments) {
44
+ comments = this.consumeLeadingCommentsOfX(key, true, consumeLeadingComments);
45
+ }
46
+ return [
47
+ comments,
48
+ this.path.call((p) => p.call((p) => f(p.call(this.print, "Node")), key), "children"),
49
+ ];
50
+ }
51
+ else if (exports.isNodeVecChild(child)) {
52
+ if (typeof transform === "function") {
53
+ f = transform;
54
+ }
55
+ let comments = "";
56
+ if (consumeLeadingComments) {
57
+ comments = this.consumeLeadingCommentsOfX(key, true, consumeLeadingComments);
58
+ }
59
+ return [
60
+ comments,
61
+ this.path.call((p) => p.call((p) => join(sep || "", p.map(this.print, "NodeVec").map(f)), key), "children"),
62
+ ];
63
+ }
64
+ // in the case of `child` is undefined
65
+ return "";
66
+ }
67
+ consumeAllCommentsOfX(key) {
68
+ let res = "";
69
+ const child = this.children[key];
70
+ if (exports.isNodeChild(child)) {
71
+ const leading_comments = child.Node.children.leading_comments;
72
+ if (leading_comments) {
73
+ res = leading_comments.NodeVec.map((x) => lineSuffix([" ", x.token.literal]));
74
+ }
75
+ const trailing_comments = child.Node.children.trailing_comments;
76
+ if (trailing_comments) {
77
+ res = [
78
+ res,
79
+ trailing_comments.NodeVec.map((x) => lineSuffix([" ", x.token.literal])),
80
+ ];
81
+ }
82
+ }
83
+ return res;
84
+ }
85
+ consumeLeadingCommentsOfSelf() {
86
+ const leading_comments = this.children["leading_comments"];
87
+ if (leading_comments) {
88
+ const res = leading_comments.NodeVec.map((x) => lineSuffix([" ", x.token.literal]));
89
+ delete this.children.leading_comments;
90
+ return res;
91
+ }
92
+ return "";
93
+ }
94
+ consumeLeadingCommentsOfX(key, asLineSuffix = true, target = "first") {
95
+ if (target === "first") {
96
+ const firstNode = this.getFirstNode(key);
97
+ if (!firstNode) {
98
+ return "";
99
+ }
100
+ const leading_comments = firstNode.children.leading_comments;
101
+ if (leading_comments) {
102
+ const res = leading_comments.NodeVec.map((x) => asLineSuffix
103
+ ? lineSuffix([" ", x.token.literal])
104
+ : [x.token.literal, hardline]);
105
+ delete firstNode.children.leading_comments;
106
+ return res;
107
+ }
108
+ else {
109
+ return "";
110
+ }
111
+ }
112
+ else if (target === "all") {
113
+ const child = this.children[key];
114
+ let firstNodes = [];
115
+ if (exports.isNodeChild(child)) {
116
+ firstNodes = [getFirstNode(child.Node)];
117
+ }
118
+ else if (exports.isNodeVecChild(child)) {
119
+ firstNodes = child.NodeVec.map((x) => getFirstNode(x));
120
+ }
121
+ const res = [];
122
+ firstNodes.forEach((x) => {
123
+ const leading_comments = x.children.leading_comments;
124
+ if (leading_comments) {
125
+ leading_comments.NodeVec.forEach((x) => {
126
+ if (asLineSuffix) {
127
+ res.push(lineSuffix([" ", x.token.literal]));
128
+ }
129
+ else {
130
+ [x.token.literal, hardline];
131
+ }
132
+ });
133
+ delete x.children.leading_comments;
134
+ }
135
+ });
136
+ return res;
137
+ }
138
+ else {
139
+ return "";
140
+ }
141
+ }
142
+ getFirstNode(key) {
143
+ const child = this.children[key];
144
+ let firstNode;
145
+ if (exports.isNodeChild(child)) {
146
+ firstNode = getFirstNode(child.Node);
147
+ }
148
+ else if (exports.isNodeVecChild(child) && child.NodeVec.length > 0) {
149
+ firstNode = getFirstNode(child.NodeVec[0]);
150
+ }
151
+ else {
152
+ return null;
153
+ }
154
+ return firstNode;
155
+ }
156
+ has(key) {
157
+ const child = this.children[key];
158
+ if (child) {
159
+ return true;
160
+ }
161
+ false;
162
+ }
163
+ hasLeadingComments(key) {
164
+ const firstNode = this.getFirstNode(key);
165
+ if (!firstNode) {
166
+ return false;
167
+ }
168
+ return "leading_comments" in firstNode.children;
169
+ }
170
+ includedIn(arr) {
171
+ const token = this.node.token;
172
+ if (!token) {
173
+ return false;
174
+ }
175
+ const literal = token.literal.toUpperCase();
176
+ const upperCaseArr = arr.map((x) => x.toUpperCase());
177
+ return upperCaseArr.includes(literal);
178
+ }
179
+ len(key) {
180
+ const nodeVec = this.children[key];
181
+ if (exports.isNodeVecChild(nodeVec)) {
182
+ return nodeVec.NodeVec.length;
183
+ }
184
+ return 0;
185
+ }
186
+ newLine() {
187
+ if (this.node.notRoot)
188
+ return "";
189
+ if (this.node.emptyLines && 0 < this.node.emptyLines) {
190
+ return [hardline, hardline];
191
+ }
192
+ return hardline;
193
+ }
194
+ self(upperOrLower, consumeLeadingComments) {
195
+ const token = this.node.token;
196
+ if (!token) {
197
+ return "";
198
+ }
199
+ let literal = token.literal;
200
+ if (upperOrLower === "lower") {
201
+ literal = literal.toLowerCase();
202
+ }
203
+ else if (this.options.printKeywordsInUpperCase) {
204
+ if (upperOrLower === "upper") {
205
+ literal = literal.toUpperCase();
206
+ }
207
+ else if (!this.node.notGlobal && this.includedIn(keywords_1.reservedKeywords)) {
208
+ literal = literal.toUpperCase();
209
+ }
210
+ else if (this.options.printPseudoColumnsInUpperCase &&
211
+ (literal.match(/^_PARTITION/i) ||
212
+ literal.match(/^_TABLE_/i) ||
213
+ literal.match(/^_FILE_/i) ||
214
+ literal.match(/^_RAW_TIMESTAMP/i) ||
215
+ literal.match(/^_CHANGE_TYPE/i) ||
216
+ literal.match(/^_CHANGE_TIMESTAMP/i) ||
217
+ literal.match(/^_CHANGE_SEQUENCE_NUMBER/i))) {
218
+ /**
219
+ * NOTE
220
+ * Field names are not allowed to start with the (case-insensitive) prefixes _PARTITION, _TABLE_, _FILE_ and _ROW_TIMESTAMP.
221
+ * On the other hand, you can create a table named `_partitiondate` (that may cause an error).
222
+ */
223
+ literal = literal.toUpperCase();
224
+ }
225
+ }
226
+ let comments = "";
227
+ if (consumeLeadingComments) {
228
+ comments = this.consumeLeadingCommentsOfSelf();
229
+ }
230
+ return [comments, literal];
231
+ }
232
+ setBreakRecommended(key) {
233
+ const child = this.children[key];
234
+ if (exports.isNodeChild(child)) {
235
+ child.Node.breakRecommended = true;
236
+ }
237
+ }
238
+ setGroupRecommended(key) {
239
+ /**
240
+ * NOTE
241
+ * You can use this method when simply using `group()` does not work.
242
+ * e.g. when grouping a part of `this.child(key)`.
243
+ */
244
+ const child = this.children[key];
245
+ if (exports.isNodeChild(child)) {
246
+ child.Node.groupRecommended = true;
247
+ }
248
+ else if (exports.isNodeVecChild(child)) {
249
+ child.NodeVec.forEach((x) => {
250
+ x.groupRecommended = true;
251
+ });
252
+ }
253
+ }
254
+ setLiteral(key, literal) {
255
+ const child = this.children[key];
256
+ if (exports.isNodeChild(child)) {
257
+ const token = child.Node.token;
258
+ if (token) {
259
+ token.literal = literal;
260
+ }
261
+ }
262
+ }
263
+ setNotRoot(key) {
264
+ const child = this.children[key];
265
+ if (exports.isNodeChild(child)) {
266
+ child.Node.notRoot = true;
267
+ }
268
+ else if (exports.isNodeVecChild(child)) {
269
+ child.NodeVec.forEach((x) => {
270
+ x.notRoot = true;
271
+ });
272
+ }
273
+ }
274
+ setNotGlobal(key) {
275
+ const child = this.children[key];
276
+ if (exports.isNodeChild(child)) {
277
+ child.Node.notGlobal = true;
278
+ }
279
+ }
280
+ toUpper(key) {
281
+ const child = this.children[key];
282
+ if (!this.options.printKeywordsInUpperCase) {
283
+ return;
284
+ }
285
+ if (exports.isNodeChild(child)) {
286
+ const token = child.Node.token;
287
+ if (token) {
288
+ token.literal = token.literal.toUpperCase();
289
+ }
290
+ }
291
+ else if (exports.isNodeVecChild(child)) {
292
+ child.NodeVec.forEach((x) => {
293
+ const token = x.token;
294
+ if (token) {
295
+ token.literal = token.literal.toUpperCase();
296
+ }
297
+ });
298
+ }
299
+ }
300
+ }
301
+ const getFirstNode = (node, includeComment = false) => {
302
+ const candidates = [];
303
+ for (const [k, v] of Object.entries(node.children)) {
304
+ if (["leading_comments", "trailing_comments"].includes(k) &&
305
+ !includeComment) {
306
+ continue;
307
+ }
308
+ if (exports.isNodeChild(v)) {
309
+ candidates.push(getFirstNode(v.Node, includeComment));
310
+ }
311
+ else if (exports.isNodeVecChild(v)) {
312
+ // NOTE maybe you don't have to check 2nd, 3rd, or latter node
313
+ v.NodeVec.forEach((x) => candidates.push(getFirstNode(x, includeComment)));
314
+ }
315
+ }
316
+ let res = node;
317
+ for (const c of candidates) {
318
+ if (!c.token) {
319
+ continue;
320
+ }
321
+ if (!res.token) {
322
+ res = c;
323
+ continue;
324
+ }
325
+ if (c.token.line < res.token.line ||
326
+ (c.token.line === res.token.line && c.token.column < res.token.column)) {
327
+ res = c;
328
+ }
329
+ }
330
+ return res;
331
+ };
332
+ const printSQL = (path, options, print) => {
333
+ const node = path.getValue();
334
+ if (Array.isArray(node)) {
335
+ for (let i = 0; i < node.length - 1; i++) {
336
+ const endNode = node[i];
337
+ if ("semicolon" in endNode.children) {
338
+ // end of statement
339
+ const semicolon = endNode.children.semicolon;
340
+ if (semicolon) {
341
+ let endLine = semicolon.Node.token.line;
342
+ const trailing_comments = semicolon.Node.children.trailing_comments;
343
+ if (trailing_comments) {
344
+ const comments = trailing_comments.NodeVec;
345
+ const len = comments.length;
346
+ const last_comments = comments[len - 1];
347
+ endLine = last_comments.token.line;
348
+ const endLiteral = last_comments.token.literal;
349
+ const newLines = endLiteral.match(/\n/g);
350
+ if (newLines) {
351
+ endLine += newLines.length;
352
+ }
353
+ }
354
+ // start of statement
355
+ const startNode = getFirstNode(node[i + 1], true);
356
+ let startLine;
357
+ if (startNode.token) {
358
+ startLine = startNode.token.line;
359
+ }
360
+ else {
361
+ // EOF
362
+ startLine = endLine + 1;
363
+ }
364
+ node[i].emptyLines = startLine - endLine - 1; // >= -1
365
+ }
366
+ }
367
+ }
368
+ return path.map(print);
369
+ }
370
+ switch (node.node_type) {
371
+ case "AccessOperator":
372
+ return printAccessOperator(path, options, print, node);
373
+ case "AddColumnClause":
374
+ return printAddColumnClause(path, options, print, node);
375
+ case "AddConstraintClause":
376
+ return printAddConstraintClause(path, options, print, node);
377
+ case "AlterBICapacityStatement":
378
+ return printAlterBICapacityStatement(path, options, print, node);
379
+ case "AlterColumnStatement":
380
+ return printAlterColumnStatement(path, options, print, node);
381
+ case "AlterOrganizationStatement":
382
+ return printAlterOrganizationStatement(path, options, print, node);
383
+ case "AlterProjectStatement":
384
+ return printAlterProjectStatement(path, options, print, node);
385
+ case "AlterReservationStatement":
386
+ return printAlterReservationStatement(path, options, print, node);
387
+ case "AlterTableDropClause":
388
+ return printAlterTableDropClause(path, options, print, node);
389
+ case "AlterSchemaStatement":
390
+ return printAlterSchemaStatement(path, options, print, node);
391
+ case "AlterTableStatement":
392
+ return printAlterTableStatement(path, options, print, node);
393
+ case "AlterViewStatement":
394
+ return printAlterViewStatement(path, options, print, node);
395
+ case "ArrayLiteral":
396
+ return printArrayLiteral(path, options, print, node);
397
+ case "AssertStatement":
398
+ return printAssertStatement(path, options, print, node);
399
+ case "Asterisk":
400
+ return printAsterisk(path, options, print, node);
401
+ case "BeginStatement":
402
+ return printBeginStatement(path, options, print, node);
403
+ case "BetweenOperator":
404
+ return printBetweenOperator(path, options, print, node);
405
+ case "BooleanLiteral":
406
+ return printBooleanLiteral(path, options, print, node);
407
+ case "BinaryOperator":
408
+ return printBinaryOperator(path, options, print, node);
409
+ case "BreakContinueStatement":
410
+ return printBreakContinueStatement(path, options, print, node);
411
+ case "CallingFunction":
412
+ return printCallingFunction(path, options, print, node);
413
+ case "CallingTableFunction":
414
+ return printCallingTableFunction(path, options, print, node);
415
+ case "CallingUnnest":
416
+ return printCallingUnnest(path, options, print, node);
417
+ case "CallStatement":
418
+ return printCallStatement(path, options, print, node);
419
+ case "CaseExpr":
420
+ return printCaseExpr(path, options, print, node);
421
+ case "CaseExprArm":
422
+ return printCaseExprArm(path, options, print, node);
423
+ case "CastArgument":
424
+ return printCastArgument(path, options, print, node);
425
+ case "Comment":
426
+ return printComment(path, options, print, node);
427
+ case "Constraint":
428
+ return printConstraint(path, options, print, node);
429
+ case "CreateFunctionStatement":
430
+ return printCreateFunctionStatement(path, options, print, node);
431
+ case "CreateProcedureStatement":
432
+ return printCreateProcedureStatement(path, options, print, node);
433
+ case "CreateReservationStatement":
434
+ return printCreateReservationStatement(path, options, print, node);
435
+ case "CreateRowAccessPolicyStatement":
436
+ return printCreateRowAccessPolicyStatement(path, options, print, node);
437
+ case "CreateSchemaStatement":
438
+ return printCreateSchemaStatement(path, options, print, node);
439
+ case "CreateSearchIndexStatement":
440
+ return printCreateSearchIndexStatement(path, options, print, node);
441
+ case "CreateTableStatement":
442
+ return printCreateTableStatement(path, options, print, node);
443
+ case "CreateViewStatement":
444
+ return printCreateViewStatement(path, options, print, node);
445
+ case "DeclareStatement":
446
+ return printDeclareStatement(path, options, print, node);
447
+ case "DeleteStatement":
448
+ return printDeleteStatement(path, options, print, node);
449
+ case "DifferentialPrivacyClause":
450
+ return printDifferentialPrivacyClause(path, options, print, node);
451
+ case "DotOperator":
452
+ return printDotOperator(path, options, print, node);
453
+ case "DropRowAccessPolicyStatement":
454
+ return printDropRowAccessPolicyStatement(path, options, print, node);
455
+ case "DropStatement":
456
+ return printDropStatement(path, options, print, node);
457
+ case "ElseIfClause":
458
+ return printElseIfClause(path, options, print, node);
459
+ case "EOF":
460
+ return printEOF(path, options, print, node);
461
+ case "ExecuteStatement":
462
+ return printExecuteStatement(path, options, print, node);
463
+ case "ExportStatement":
464
+ return printExportStatement(path, options, print, node);
465
+ case "ExtractArgument":
466
+ return printExtractArgument(path, options, print, node);
467
+ case "ForStatement":
468
+ return printForStatement(path, options, print, node);
469
+ case "ForSystemTimeAsOfClause":
470
+ return printForSystemTimeAsOfclause(path, options, print, node);
471
+ case "GrantStatement":
472
+ return printGrantStatement(path, options, print, node);
473
+ case "GroupedExpr":
474
+ return printGroupedExpr(path, options, print, node);
475
+ case "GroupedExprs":
476
+ return printGroupedExprs(path, options, print, node);
477
+ case "GroupedIdentWithOptions":
478
+ return printGroupedIdentWithOptions(path, options, print, node);
479
+ case "GroupedStatement":
480
+ return printGroupedStatement(path, options, print, node);
481
+ case "GroupedType":
482
+ return printGroupedType(path, options, print, node);
483
+ case "GroupedTypeDeclarationOrConstraints":
484
+ return printGroupedTypeDeclarations(path, options, print, node);
485
+ case "Identifier":
486
+ return printIdentifier(path, options, print, node);
487
+ case "IdentWithOptions":
488
+ return printIdentWithOptions(path, options, print, node);
489
+ case "IfStatement":
490
+ return printIfStatement(path, options, print, node);
491
+ case "InOperator":
492
+ return printInOperator(path, options, print, node);
493
+ case "InsertStatement":
494
+ return printInsertStatement(path, options, print, node);
495
+ case "IntervalLiteral":
496
+ return printIntervalLiteral(path, options, print, node);
497
+ case "IsDistinctFromOperator":
498
+ return printIsDistinctFromOperator(path, options, print, node);
499
+ case "JoinOperator":
500
+ return printJoinOperator(path, options, print, node);
501
+ case "Keyword":
502
+ return printKeyword(path, options, print, node);
503
+ case "KeywordSequence":
504
+ return printKeywordSequence(path, options, print, node);
505
+ case "KeywordWithExpr":
506
+ return printKeywordWithExpr(path, options, print, node);
507
+ case "KeywordWithExprs":
508
+ return printKeywordWithExprs(path, options, print, node);
509
+ case "KeywordWithGroupedXXX":
510
+ return printKeywordWithGroupedXXX(path, options, print, node);
511
+ case "KeywordWithStatement":
512
+ return printKeywordWithStatement(path, options, print, node);
513
+ case "KeywordWithStatements":
514
+ return printKeywordWithStatements(path, options, print, node);
515
+ case "KeywordWithType":
516
+ return printKeywordWithType(path, options, print, node);
517
+ case "LimitClause":
518
+ return printLimitClause(path, options, print, node);
519
+ case "LoadStatement":
520
+ return printLoadStatement(path, options, print, node);
521
+ case "LoopStatement":
522
+ return printLoopStatement(path, options, print, node);
523
+ case "MergeStatement":
524
+ return printMergeStatement(path, options, print, node);
525
+ case "MultiTokenIdentifier":
526
+ return printMultiTokenIdentifier(path, options, print, node);
527
+ case "NullLiteral":
528
+ return printNullLiteral(path, options, print, node);
529
+ case "NumericLiteral":
530
+ return printNumericLiteral(path, options, print, node);
531
+ case "OverClause":
532
+ return printOverClause(path, options, print, node);
533
+ case "Parameter":
534
+ return printIdentifier(path, options, print, node);
535
+ case "PivotConfig":
536
+ return printPivotConfig(path, options, print, node);
537
+ case "PivotOperator":
538
+ return printPivotOperator(path, options, print, node);
539
+ case "RevokeStatement":
540
+ return printRevokeStatement(path, options, print, node);
541
+ case "RaiseStatement":
542
+ return printRaiseStatement(path, options, print, node);
543
+ case "RenameColumnClause":
544
+ return printRenameColumnClause(path, options, print, node);
545
+ case "RepeatStatement":
546
+ return printRepeatStatement(path, options, print, node);
547
+ case "SelectStatement":
548
+ return printSelectStatement(path, options, print, node);
549
+ case "SetOperator":
550
+ return printSetOperator(path, options, print, node);
551
+ case "SetStatement":
552
+ return printSetStatement(path, options, print, node);
553
+ case "SingleTokenStatement":
554
+ return printSingleTokenStatement(path, options, print, node);
555
+ case "StringLiteral":
556
+ return printStringLiteral(path, options, print, node);
557
+ case "StructLiteral":
558
+ return printStructLiteral(path, options, print, node);
559
+ case "Symbol":
560
+ return printSymbol(path, options, print, node);
561
+ case "TableSampleClause":
562
+ return printTableSampleClause(path, options, print, node);
563
+ case "TableSampleRatio":
564
+ return printTableSampleRatio(path, options, print, node);
565
+ case "Template":
566
+ return printIdentifier(path, options, print, node);
567
+ case "TransactionStatement":
568
+ return printTransactionStatement(path, options, print, node);
569
+ case "TruncateStatement":
570
+ return printTruncateStatement(path, options, print, node);
571
+ case "Type":
572
+ return printType(path, options, print, node);
573
+ case "TypeDeclaration":
574
+ return printTypeDeclaration(path, options, print, node);
575
+ case "UnaryOperator":
576
+ return printUnaryOperator(path, options, print, node);
577
+ case "UnpivotConfig":
578
+ return printUnpivotConfig(path, options, print, node);
579
+ case "UnpivotOperator":
580
+ return printUnpivotOperator(path, options, print, node);
581
+ case "UpdateStatement":
582
+ return printUpdateStatement(path, options, print, node);
583
+ case "WhenClause":
584
+ return printWhenClause(path, options, print, node);
585
+ case "WhileStatement":
586
+ return printWhileStatement(path, options, print, node);
587
+ case "WindowClause":
588
+ return printWindowClause(path, options, print, node);
589
+ case "WindowExpr":
590
+ return printWindowExpr(path, options, print, node);
591
+ case "WindowFrameClause":
592
+ return printWindowFrameClause(path, options, print, node);
593
+ case "WindowSpecification":
594
+ return printWindowSpecification(path, options, print, node);
595
+ case "WithClause":
596
+ return printWithClause(path, options, print, node);
597
+ case "WithPartitionColumnsClause":
598
+ return printWithPartitionColumnsClause(path, options, print, node);
599
+ case "WithQuery":
600
+ return printWithQuery(path, options, print, node);
601
+ case "XXXByExprs":
602
+ return printXXXByExprs(path, options, print, node);
603
+ default:
604
+ throw new Error(`Not implemented node type: ${JSON.stringify(node)}`);
605
+ }
606
+ };
607
+ exports.printSQL = printSQL;
608
+ const printAccessOperator = (path, options, print, node) => {
609
+ const p = new Printer(path, options, print, node);
610
+ const docs = {
611
+ leading_comments: "",
612
+ left: p.child("left"),
613
+ self: p.self("asItIs", true),
614
+ trailing_comments: printTrailingComments(path, options, print, node),
615
+ right: p.child("right", undefined, "all"),
616
+ rparen: p.child("rparen", undefined, "all"),
617
+ as: "",
618
+ alias: printAlias(path, options, print, node),
619
+ order: printOrder(path, options, print, node),
620
+ null_order: "",
621
+ comma: printComma(path, options, print, node),
622
+ };
623
+ return [
624
+ group([
625
+ docs.left,
626
+ docs.self,
627
+ docs.trailing_comments,
628
+ docs.right,
629
+ docs.rparen,
630
+ docs.alias,
631
+ docs.order,
632
+ ]),
633
+ docs.comma,
634
+ ];
635
+ };
636
+ const printAddColumnClause = (path, options, print, node) => {
637
+ const p = new Printer(path, options, print, node);
638
+ const docs = {
639
+ leading_comments: printLeadingComments(path, options, print, node),
640
+ self: p.self("upper"),
641
+ trailing_comments: printTrailingComments(path, options, print, node),
642
+ what: p.child("what", undefined, "all"),
643
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
644
+ type_declaration: p.child("type_declaration"),
645
+ comma: p.child("comma", undefined, "all"),
646
+ };
647
+ return [
648
+ docs.leading_comments,
649
+ group([
650
+ docs.self,
651
+ docs.trailing_comments,
652
+ " ",
653
+ docs.what,
654
+ docs.if_not_exists,
655
+ " ",
656
+ docs.type_declaration,
657
+ docs.comma,
658
+ ]),
659
+ ];
660
+ };
661
+ const printAddConstraintClause = (path, options, print, node) => {
662
+ const p = new Printer(path, options, print, node);
663
+ const docs = {
664
+ leading_comments: printLeadingComments(path, options, print, node),
665
+ self: p.self("upper"),
666
+ trailing_comments: printTrailingComments(path, options, print, node),
667
+ what: p.child("what", undefined, "all"),
668
+ comma: p.child("comma", undefined, "all"),
669
+ };
670
+ return [
671
+ docs.leading_comments,
672
+ group([docs.self, docs.trailing_comments, " ", docs.what, docs.comma]),
673
+ ];
674
+ };
675
+ const printAlterBICapacityStatement = (path, options, print, node) => {
676
+ const p = new Printer(path, options, print, node);
677
+ const docs = {
678
+ leading_comments: printLeadingComments(path, options, print, node),
679
+ self: p.self("upper"),
680
+ trailing_comments: printTrailingComments(path, options, print, node),
681
+ what: p.child("what", undefined, "all"),
682
+ ident: p.child("ident", undefined, "all"),
683
+ set: p.child("set"),
684
+ options: p.child("options", undefined, "all"),
685
+ semicolon: p.child("semicolon"),
686
+ };
687
+ return [
688
+ docs.leading_comments,
689
+ group([
690
+ docs.self,
691
+ docs.trailing_comments,
692
+ " ",
693
+ docs.what,
694
+ " ",
695
+ docs.ident,
696
+ line,
697
+ docs.set,
698
+ " ",
699
+ docs.options,
700
+ softline,
701
+ docs.semicolon,
702
+ ]),
703
+ p.newLine(),
704
+ ];
705
+ };
706
+ const printAlterColumnStatement = (path, options, print, node) => {
707
+ const p = new Printer(path, options, print, node);
708
+ const docs = {
709
+ leading_comments: printLeadingComments(path, options, print, node),
710
+ self: p.self("upper"),
711
+ trailing_comments: printTrailingComments(path, options, print, node),
712
+ what: p.child("what", undefined, "all"),
713
+ if_exists: p.child("if_exists", (x) => group([line, x])),
714
+ ident: p.child("ident", undefined, "all"),
715
+ set: p.child("set"),
716
+ data_type: p.child("data_type", undefined, "all", " "),
717
+ type: p.child("type", undefined, "all"),
718
+ default: p.child("default", undefined, "all"),
719
+ options: p.child("options", undefined, "all"),
720
+ drop_not_null: p.child("drop_not_null", (x) => group([line, x])),
721
+ drop_default: p.child("drop_default", (x) => group([line, x])),
722
+ };
723
+ return [
724
+ docs.leading_comments,
725
+ group([
726
+ docs.self,
727
+ docs.trailing_comments,
728
+ " ",
729
+ docs.what,
730
+ docs.if_exists,
731
+ " ",
732
+ docs.ident,
733
+ p.has("set") ? line : "",
734
+ docs.set,
735
+ p.has("data_type") ? " " : "",
736
+ docs.data_type,
737
+ p.has("type") ? " " : "",
738
+ docs.type,
739
+ p.has("default") ? " " : "",
740
+ docs.default,
741
+ p.has("options") ? " " : "",
742
+ docs.options,
743
+ docs.drop_not_null,
744
+ docs.drop_default,
745
+ ]),
746
+ ];
747
+ };
748
+ const printAlterOrganizationStatement = (path, options, print, node) => {
749
+ const p = new Printer(path, options, print, node);
750
+ const docs = {
751
+ leading_comments: printLeadingComments(path, options, print, node),
752
+ self: p.self("upper"),
753
+ trailing_comments: printTrailingComments(path, options, print, node),
754
+ what: p.child("what", undefined, "all"),
755
+ set: p.child("set"),
756
+ options: p.child("options", undefined, "all"),
757
+ semicolon: p.child("semicolon"),
758
+ };
759
+ return [
760
+ docs.leading_comments,
761
+ group([
762
+ docs.self,
763
+ docs.trailing_comments,
764
+ " ",
765
+ docs.what,
766
+ line,
767
+ docs.set,
768
+ " ",
769
+ docs.options,
770
+ softline,
771
+ docs.semicolon,
772
+ ]),
773
+ p.newLine(),
774
+ ];
775
+ };
776
+ const printAlterProjectStatement = (path, options, print, node) => {
777
+ const p = new Printer(path, options, print, node);
778
+ const docs = {
779
+ leading_comments: printLeadingComments(path, options, print, node),
780
+ self: p.self("upper"),
781
+ trailing_comments: printTrailingComments(path, options, print, node),
782
+ what: p.child("what", undefined, "all"),
783
+ ident: p.child("ident", undefined, "all"),
784
+ set: p.child("set"),
785
+ options: p.child("options", undefined, "all"),
786
+ semicolon: p.child("semicolon"),
787
+ };
788
+ return [
789
+ docs.leading_comments,
790
+ group([
791
+ docs.self,
792
+ docs.trailing_comments,
793
+ " ",
794
+ docs.what,
795
+ p.has("ident") ? " " : "",
796
+ docs.ident,
797
+ line,
798
+ docs.set,
799
+ " ",
800
+ docs.options,
801
+ softline,
802
+ docs.semicolon,
803
+ ]),
804
+ p.newLine(),
805
+ ];
806
+ };
807
+ const printAlterReservationStatement = (path, options, print, node) => {
808
+ const p = new Printer(path, options, print, node);
809
+ const docs = {
810
+ leading_comments: printLeadingComments(path, options, print, node),
811
+ self: p.self("upper"),
812
+ trailing_comments: printTrailingComments(path, options, print, node),
813
+ what: p.child("what", undefined, "all"),
814
+ ident: p.child("ident", undefined, "all"),
815
+ set: p.child("set"),
816
+ options: p.child("options", undefined, "all"),
817
+ semicolon: p.child("semicolon"),
818
+ };
819
+ return [
820
+ docs.leading_comments,
821
+ group([
822
+ docs.self,
823
+ docs.trailing_comments,
824
+ " ",
825
+ docs.what,
826
+ " ",
827
+ docs.ident,
828
+ line,
829
+ docs.set,
830
+ " ",
831
+ docs.options,
832
+ softline,
833
+ docs.semicolon,
834
+ ]),
835
+ p.newLine(),
836
+ ];
837
+ };
838
+ const printAlterSchemaStatement = (path, options, print, node) => {
839
+ const p = new Printer(path, options, print, node);
840
+ const docs = {
841
+ leading_comments: printLeadingComments(path, options, print, node),
842
+ self: p.self("upper"),
843
+ trailing_comments: printTrailingComments(path, options, print, node),
844
+ what: p.child("what", undefined, "all"),
845
+ if_exists: p.child("if_exists", (x) => group([line, x])),
846
+ ident: p.child("ident", undefined, "all"),
847
+ set: p.child("set"),
848
+ options: p.child("options", undefined, "all"),
849
+ default_collate: p.child("default_collate", undefined, "all"),
850
+ semicolon: p.child("semicolon"),
851
+ };
852
+ return [
853
+ docs.leading_comments,
854
+ group([
855
+ docs.self,
856
+ docs.trailing_comments,
857
+ " ",
858
+ docs.what,
859
+ docs.if_exists,
860
+ p.has("ident") ? " " : "",
861
+ docs.ident,
862
+ line,
863
+ docs.set,
864
+ " ",
865
+ docs.default_collate,
866
+ docs.options,
867
+ softline,
868
+ docs.semicolon,
869
+ ]),
870
+ p.newLine(),
871
+ ];
872
+ };
873
+ const printAlterTableDropClause = (path, options, print, node) => {
874
+ const p = new Printer(path, options, print, node);
875
+ const docs = {
876
+ leading_comments: printLeadingComments(path, options, print, node),
877
+ self: p.self("upper"),
878
+ trailing_comments: printTrailingComments(path, options, print, node),
879
+ what: p.child("what", undefined, "all"),
880
+ if_exists: p.child("if_exists", (x) => group([line, x])),
881
+ ident: p.child("ident", undefined, "all"),
882
+ comma: p.child("comma", undefined, "all"),
883
+ };
884
+ return [
885
+ docs.leading_comments,
886
+ group([
887
+ docs.self,
888
+ " ",
889
+ docs.what,
890
+ docs.trailing_comments,
891
+ docs.if_exists,
892
+ p.has("ident") ? " " : "",
893
+ docs.ident,
894
+ docs.comma,
895
+ ]),
896
+ ];
897
+ };
898
+ const printAlterTableStatement = (path, options, print, node) => {
899
+ const p = new Printer(path, options, print, node);
900
+ const docs = {
901
+ leading_comments: printLeadingComments(path, options, print, node),
902
+ self: p.self("upper"),
903
+ trailing_comments: printTrailingComments(path, options, print, node),
904
+ what: p.child("what", undefined, "all"),
905
+ if_exists: p.child("if_exists", (x) => group([line, x])),
906
+ ident: p.child("ident", undefined, "all"),
907
+ // SET
908
+ set: p.child("set"),
909
+ options: p.child("options", undefined, "all"),
910
+ default_collate: p.child("default_collate", undefined, "all"),
911
+ // ADD COLUMNS
912
+ add_columns: p.child("add_columns", (x) => [line, x]),
913
+ // ADD CONSTRAINT
914
+ add_constraints: p.child("add_constraints", (x) => [line, x]),
915
+ // RENAMTE TO
916
+ rename: p.child("rename"),
917
+ to: p.child("to", undefined, "all"),
918
+ // RENAMTE COLUMN
919
+ rename_columns: p.child("rename_columns", (x) => [hardline, x]),
920
+ // DROP COLUMNS
921
+ drop_columns: p.child("drop_columns", (x) => [hardline, x]),
922
+ // ALTER COLUMN satatement
923
+ alter_column_stmt: p.child("alter_column_stmt"),
924
+ semicolon: p.child("semicolon"),
925
+ };
926
+ return [
927
+ docs.leading_comments,
928
+ group([
929
+ docs.self,
930
+ docs.trailing_comments,
931
+ " ",
932
+ docs.what,
933
+ docs.if_exists,
934
+ p.has("ident") ? " " : "",
935
+ docs.ident,
936
+ p.has("set") ? line : "",
937
+ docs.set,
938
+ p.has("set") ? " " : "",
939
+ docs.options,
940
+ docs.default_collate,
941
+ docs.add_columns,
942
+ docs.add_constraints,
943
+ p.has("rename") ? line : "",
944
+ docs.rename,
945
+ p.has("rename") ? " " : "",
946
+ docs.to,
947
+ docs.rename_columns,
948
+ docs.drop_columns,
949
+ p.has("alter_column_stmt") ? hardline : "",
950
+ docs.alter_column_stmt,
951
+ softline,
952
+ docs.semicolon,
953
+ ]),
954
+ p.newLine(),
955
+ ];
956
+ };
957
+ const printAlterViewStatement = (path, options, print, node) => {
958
+ const p = new Printer(path, options, print, node);
959
+ const docs = {
960
+ leading_comments: printLeadingComments(path, options, print, node),
961
+ self: p.self("upper"),
962
+ trailing_comments: printTrailingComments(path, options, print, node),
963
+ materialized: p.child("materialized", undefined, "all"),
964
+ what: p.child("what", undefined, "all"),
965
+ if_exists: p.child("if_exists", (x) => group([line, x])),
966
+ ident: p.child("ident", undefined, "all"),
967
+ set: p.child("set"),
968
+ options: p.child("options", undefined, "all"),
969
+ alter_column_stmt: p.child("alter_column_stmt"),
970
+ semicolon: p.child("semicolon"),
971
+ };
972
+ return [
973
+ docs.leading_comments,
974
+ group([
975
+ docs.self,
976
+ docs.trailing_comments,
977
+ p.has("materialized") ? " " : "",
978
+ docs.materialized,
979
+ " ",
980
+ docs.what,
981
+ docs.if_exists,
982
+ p.has("ident") ? " " : "",
983
+ docs.ident,
984
+ line,
985
+ docs.set,
986
+ p.has("set") ? " " : "",
987
+ docs.options,
988
+ docs.alter_column_stmt,
989
+ softline,
990
+ docs.semicolon,
991
+ ]),
992
+ p.newLine(),
993
+ ];
994
+ };
995
+ const printAsterisk = (path, options, print, node) => {
996
+ const p = new Printer(path, options, print, node);
997
+ const docs = {
998
+ leading_comments: printLeadingComments(path, options, print, node),
999
+ self: p.self(),
1000
+ trailing_comments: printTrailingComments(path, options, print, node),
1001
+ except: p.child("except", (x) => [" ", x], "all"),
1002
+ replace: p.child("replace", (x) => [" ", x], "all"),
1003
+ as: "",
1004
+ alias: printAlias(path, options, print, node),
1005
+ comma: printComma(path, options, print, node),
1006
+ };
1007
+ return [
1008
+ docs.leading_comments,
1009
+ docs.self,
1010
+ docs.trailing_comments,
1011
+ docs.except,
1012
+ docs.replace,
1013
+ docs.alias,
1014
+ docs.comma,
1015
+ ];
1016
+ };
1017
+ const printArrayLiteral = (path, options, print, node) => {
1018
+ const p = new Printer(path, options, print, node);
1019
+ const docs = {
1020
+ type: p.child("type"),
1021
+ leading_comments: p.has("type")
1022
+ ? ""
1023
+ : printLeadingComments(path, options, print, node),
1024
+ self: p.has("type") ? p.self("asItIs", true) : p.self(),
1025
+ trailing_comments: printTrailingComments(path, options, print, node),
1026
+ exprs: p.child("exprs", (x) => group(x), "none", line),
1027
+ rparen: p.child("rparen"),
1028
+ as: "",
1029
+ alias: printAlias(path, options, print, node),
1030
+ order: printOrder(path, options, print, node),
1031
+ null_order: "",
1032
+ comma: printComma(path, options, print, node),
1033
+ };
1034
+ return [
1035
+ group([
1036
+ docs.type,
1037
+ docs.leading_comments,
1038
+ group([
1039
+ docs.self,
1040
+ docs.trailing_comments,
1041
+ indent([softline, docs.exprs]),
1042
+ softline,
1043
+ docs.rparen,
1044
+ docs.alias,
1045
+ docs.order,
1046
+ ]),
1047
+ ]),
1048
+ docs.comma,
1049
+ ];
1050
+ };
1051
+ const printAssertStatement = (path, options, print, node) => {
1052
+ const p = new Printer(path, options, print, node);
1053
+ const docs = {
1054
+ leading_comments: printLeadingComments(path, options, print, node),
1055
+ self: p.self("upper"),
1056
+ trailing_comments: printTrailingComments(path, options, print, node),
1057
+ expr: !p.hasLeadingComments("expr") &&
1058
+ ["GroupedExpr", "GroupedStatement", "CallingFunction"].includes(node.children.expr.Node.node_type)
1059
+ ? [" ", p.child("expr", undefined, "all")]
1060
+ : indent([line, p.child("expr")]),
1061
+ as: p.child("as"),
1062
+ description: p.child("description", undefined, "all"),
1063
+ semicolon: p.child("semicolon"),
1064
+ };
1065
+ return [
1066
+ docs.leading_comments,
1067
+ group([
1068
+ docs.self,
1069
+ docs.trailing_comments,
1070
+ docs.expr,
1071
+ p.has("as") ? line : "",
1072
+ docs.as,
1073
+ p.has("description") ? " " : "",
1074
+ docs.description,
1075
+ softline,
1076
+ docs.semicolon,
1077
+ ]),
1078
+ p.newLine(),
1079
+ ];
1080
+ };
1081
+ const printBeginStatement = (path, options, print, node) => {
1082
+ const p = new Printer(path, options, print, node);
1083
+ p.setNotRoot("stmts");
1084
+ let leading_label_comments = "";
1085
+ if (node.children.leading_label &&
1086
+ node.children.leading_label.Node.children.leading_comments) {
1087
+ leading_label_comments =
1088
+ node.children.leading_label.Node.children.leading_comments.NodeVec.map((n) => [n.token.literal, hardline]);
1089
+ p.consumeLeadingCommentsOfX("leading_label");
1090
+ }
1091
+ const docs = {
1092
+ leading_label: p.child("leading_label"),
1093
+ colon: p.child("colon", undefined, "all"),
1094
+ leading_comments: printLeadingComments(path, options, print, node),
1095
+ self: p.self("upper"),
1096
+ trailing_comments: printTrailingComments(path, options, print, node),
1097
+ stmts: p.len("stmts") <= 1
1098
+ ? p.child("stmts", (x) => [line, x])
1099
+ : p.child("stmts", (x) => [hardline, x]),
1100
+ exception_when_error: group(p.child("exception_when_error", undefined, "none", line)),
1101
+ then: p.child("then", undefined, "all"),
1102
+ end: p.child("end"),
1103
+ trailing_label: p.child("trailing_label", undefined, "all"),
1104
+ semicolon: p.child("semicolon"),
1105
+ };
1106
+ return [
1107
+ leading_label_comments,
1108
+ docs.leading_comments,
1109
+ group([
1110
+ docs.leading_label,
1111
+ docs.colon,
1112
+ p.has("leading_label") ? " " : "",
1113
+ docs.self,
1114
+ docs.trailing_comments,
1115
+ indent(docs.stmts),
1116
+ p.has("exception_when_error") ? hardline : "",
1117
+ docs.exception_when_error,
1118
+ p.has("then") ? " " : "",
1119
+ docs.then,
1120
+ line,
1121
+ docs.end,
1122
+ p.has("trailing_label") ? " " : "",
1123
+ docs.trailing_label,
1124
+ softline,
1125
+ docs.semicolon,
1126
+ ]),
1127
+ p.newLine(),
1128
+ ];
1129
+ };
1130
+ const printBetweenOperator = (path, options, print, node) => {
1131
+ const p = new Printer(path, options, print, node);
1132
+ const docs = {
1133
+ leading_comments: "",
1134
+ left: p.child("left"),
1135
+ not: p.child("not", undefined, "all"),
1136
+ self: p.self("upper", true),
1137
+ trailing_comments: printTrailingComments(path, options, print, node),
1138
+ right_min: p.child("right_min"),
1139
+ and: p.child("and"),
1140
+ right_max: p.child("right_max", undefined, "all"),
1141
+ as: "",
1142
+ alias: printAlias(path, options, print, node),
1143
+ order: printOrder(path, options, print, node),
1144
+ null_order: "",
1145
+ comma: printComma(path, options, print, node),
1146
+ };
1147
+ return [
1148
+ docs.left,
1149
+ " ",
1150
+ p.has("not") ? [docs.not, " "] : "",
1151
+ group([
1152
+ docs.self,
1153
+ docs.trailing_comments,
1154
+ indent([
1155
+ line,
1156
+ group(docs.right_min),
1157
+ line,
1158
+ group([docs.and, " ", docs.right_max]),
1159
+ docs.alias,
1160
+ docs.order,
1161
+ ]),
1162
+ ]),
1163
+ docs.comma,
1164
+ ];
1165
+ };
1166
+ const printBooleanLiteral = (path, options, print, node) => {
1167
+ const p = new Printer(path, options, print, node);
1168
+ const docs = {
1169
+ leading_comments: printLeadingComments(path, options, print, node),
1170
+ self: p.self(),
1171
+ trailing_comments: printTrailingComments(path, options, print, node),
1172
+ as: "",
1173
+ alias: printAlias(path, options, print, node),
1174
+ order: printOrder(path, options, print, node),
1175
+ null_order: "",
1176
+ comma: printComma(path, options, print, node),
1177
+ };
1178
+ return [
1179
+ docs.leading_comments,
1180
+ docs.self,
1181
+ docs.trailing_comments,
1182
+ docs.alias,
1183
+ docs.order,
1184
+ docs.comma,
1185
+ ];
1186
+ };
1187
+ // TODO Define another function for AND, OR.
1188
+ const printBinaryOperator = (path, options, print, node) => {
1189
+ const p = new Printer(path, options, print, node);
1190
+ p.setNotRoot("left");
1191
+ p.setNotRoot("right");
1192
+ const leading_comments = p.consumeLeadingCommentsOfX("left", false);
1193
+ const logical = p.includedIn(["AND", "OR"]);
1194
+ const docs = {
1195
+ leading_comments: leading_comments,
1196
+ left: p.child("left"),
1197
+ not: p.child("not", undefined, "all"),
1198
+ self: logical ? p.self("upper") : p.self("upper", true),
1199
+ trailing_comments: printTrailingComments(path, options, print, node),
1200
+ right: p.child("right", undefined, "all"),
1201
+ as: "",
1202
+ alias: printAlias(path, options, print, node),
1203
+ order: printOrder(path, options, print, node),
1204
+ null_order: "",
1205
+ comma: printComma(path, options, print, node),
1206
+ };
1207
+ // NOTE
1208
+ // If you reassign `docs.left`, eslint-plugin-unicorn does not work.
1209
+ // So define new variable here.
1210
+ let left = docs.left;
1211
+ let right = docs.right;
1212
+ if (logical) {
1213
+ if (!["AND", "OR"].includes(p.children.left.Node.token.literal.toUpperCase())) {
1214
+ left = group(docs.left);
1215
+ }
1216
+ if (!["AND", "OR"].includes(p.children.right.Node.token.literal.toUpperCase())) {
1217
+ right = group(docs.right);
1218
+ }
1219
+ }
1220
+ else {
1221
+ if (p.children.left.Node.node_type !== "BinaryOperator") {
1222
+ left = group(docs.left);
1223
+ }
1224
+ if (p.children.right.Node.node_type !== "BinaryOperator") {
1225
+ right = group(docs.right);
1226
+ }
1227
+ }
1228
+ let res = [
1229
+ left,
1230
+ (logical && node.breakRecommended) || p.has("leading_comments")
1231
+ ? hardline
1232
+ : line,
1233
+ p.has("not") && !p.includedIn(["IS"]) ? [docs.not, " "] : "",
1234
+ // NOTE If self is not logical, leading_comments has already been consumed.
1235
+ printLeadingComments(path, options, print, node),
1236
+ docs.self,
1237
+ p.has("not") && p.includedIn(["IS"]) ? [" ", docs.not] : "",
1238
+ " ",
1239
+ docs.trailing_comments,
1240
+ right,
1241
+ ];
1242
+ if (node.groupRecommended) {
1243
+ res = group(res);
1244
+ }
1245
+ return [docs.leading_comments, res, docs.alias, docs.order, docs.comma];
1246
+ };
1247
+ const printBreakContinueStatement = (path, options, print, node) => {
1248
+ const p = new Printer(path, options, print, node);
1249
+ const docs = {
1250
+ leading_comments: printLeadingComments(path, options, print, node),
1251
+ self: p.self("upper"),
1252
+ trailing_comments: printTrailingComments(path, options, print, node),
1253
+ label: p.child("label", undefined, "all"),
1254
+ semicolon: p.child("semicolon"),
1255
+ };
1256
+ return [
1257
+ docs.leading_comments,
1258
+ docs.self,
1259
+ docs.trailing_comments,
1260
+ p.has("label") ? " " : "",
1261
+ docs.label,
1262
+ docs.semicolon,
1263
+ p.newLine(),
1264
+ ];
1265
+ };
1266
+ const printCallingFunction = (path, options, print, node) => {
1267
+ return printCallingFunctionGeneral(path, options, print, node);
1268
+ };
1269
+ const printCallingFunctionGeneral = (path, options, print, node) => {
1270
+ const p = new Printer(path, options, print, node);
1271
+ p.setNotRoot("args");
1272
+ let func = node.children.func.Node;
1273
+ let parent;
1274
+ let grandParent;
1275
+ if (node.isDatePart) {
1276
+ p.toUpper("func");
1277
+ p.toUpper("args");
1278
+ }
1279
+ const toUpper = (x) => {
1280
+ if (options.printKeywordsInUpperCase) {
1281
+ x.literal = x.literal.toUpperCase();
1282
+ }
1283
+ return x;
1284
+ };
1285
+ if (func.node_type === "Identifier") {
1286
+ // SUBSTR("foo", 0, 2)
1287
+ if (keywords_1.globalFunctions.includes(func.token.literal.toUpperCase())) {
1288
+ func.isPreDefinedFunction = true;
1289
+ }
1290
+ }
1291
+ else if (func.node_type === "DotOperator") {
1292
+ parent = func.children.left.Node;
1293
+ func = func.children.right.Node;
1294
+ if (parent.node_type === "Identifier") {
1295
+ // SAFE.SUBSTR("foo", 0, 2)
1296
+ // KEYS.NEW_KEYSET('AEAD_AES_GCM_256')
1297
+ switch (parent.token.literal.toUpperCase()) {
1298
+ case "SAFE":
1299
+ if (keywords_1.globalFunctions.includes(func.token.literal.toUpperCase())) {
1300
+ func.isPreDefinedFunction = true;
1301
+ toUpper(parent.token);
1302
+ }
1303
+ break;
1304
+ case "KEYS":
1305
+ if (keywords_1.keysFunctions.includes(func.token.literal.toUpperCase())) {
1306
+ func.isPreDefinedFunction = true;
1307
+ toUpper(parent.token);
1308
+ }
1309
+ break;
1310
+ case "AEAD":
1311
+ if (keywords_1.aeadFunctions.includes(func.token.literal.toUpperCase())) {
1312
+ func.isPreDefinedFunction = true;
1313
+ toUpper(parent.token);
1314
+ }
1315
+ break;
1316
+ case "NET":
1317
+ if (keywords_1.netFunctions.includes(func.token.literal.toUpperCase())) {
1318
+ func.isPreDefinedFunction = true;
1319
+ toUpper(parent.token);
1320
+ }
1321
+ break;
1322
+ case "HLL_COUNT":
1323
+ if (keywords_1.hllCountFunctions.includes(func.token.literal.toUpperCase())) {
1324
+ func.isPreDefinedFunction = true;
1325
+ toUpper(parent.token);
1326
+ }
1327
+ break;
1328
+ }
1329
+ }
1330
+ else if (parent.node_type === "DotOperator") {
1331
+ // SAFE.KEYS.NEW_KEYSET('AEAD_AES_GCM_256')
1332
+ grandParent = parent.children.left.Node;
1333
+ parent = parent.children.right.Node;
1334
+ if (grandParent.token.literal.toUpperCase() === "SAFE") {
1335
+ switch (parent.token.literal.toUpperCase()) {
1336
+ case "KEYS":
1337
+ if (keywords_1.keysFunctions.includes(func.token.literal.toUpperCase())) {
1338
+ func.isPreDefinedFunction = true;
1339
+ toUpper(parent.token);
1340
+ toUpper(grandParent.token);
1341
+ }
1342
+ break;
1343
+ case "AEAD":
1344
+ if (keywords_1.aeadFunctions.includes(func.token.literal.toUpperCase())) {
1345
+ func.isPreDefinedFunction = true;
1346
+ toUpper(parent.token);
1347
+ toUpper(grandParent.token);
1348
+ }
1349
+ break;
1350
+ case "NET":
1351
+ if (keywords_1.netFunctions.includes(func.token.literal.toUpperCase())) {
1352
+ func.isPreDefinedFunction = true;
1353
+ toUpper(parent.token);
1354
+ toUpper(grandParent.token);
1355
+ }
1356
+ break;
1357
+ case "HLL_COUNT":
1358
+ if (keywords_1.hllCountFunctions.includes(func.token.literal.toUpperCase())) {
1359
+ func.isPreDefinedFunction = true;
1360
+ toUpper(parent.token);
1361
+ toUpper(grandParent.token);
1362
+ }
1363
+ break;
1364
+ }
1365
+ }
1366
+ }
1367
+ }
1368
+ if (func.isPreDefinedFunction) {
1369
+ const func_literal = func.token.literal.toUpperCase();
1370
+ const args = node.children.args;
1371
+ if (args) {
1372
+ // NORMALIZE
1373
+ if (["NORMALIZE", "NORMALIZE_AND_CASEFOLD"].includes(func_literal) &&
1374
+ 2 <= p.len("args")) {
1375
+ toUpper(args.NodeVec[1].token);
1376
+ }
1377
+ // XXX_DIFF
1378
+ if (["DATE_DIFF", "DATETIME_DIFF", "TIME_DIFF", "TIMESTAMP_DIFF"].includes(func_literal)) {
1379
+ args.NodeVec[2].isDatePart = true;
1380
+ }
1381
+ // XXX_TRUNC
1382
+ if ([
1383
+ "DATE_TRUNC",
1384
+ "DATETIME_TRUNC",
1385
+ "TIME_TRUNC",
1386
+ "TIMESTAMP_TRUNC",
1387
+ ].includes(func_literal)) {
1388
+ args.NodeVec[1].isDatePart = true;
1389
+ }
1390
+ // LAST_DAY
1391
+ if (func_literal === "LAST_DAY" && 2 <= p.len("args")) {
1392
+ args.NodeVec[1].isDatePart = true;
1393
+ }
1394
+ }
1395
+ }
1396
+ const docs = {
1397
+ leading_comments: "",
1398
+ func: p.child("func"),
1399
+ self: p.self("asItIs", true),
1400
+ trailing_comments: printTrailingComments(path, options, print, node),
1401
+ distinct: p.child("distinct", (x) => [x, line]),
1402
+ args: p.child("args", (x) => group(x), "none", line),
1403
+ ignore_nulls: p.child("ignore_nulls", undefined, "none", line),
1404
+ orderby: p.child("orderby"),
1405
+ limit: p.child("limit"),
1406
+ having: p.child("having"),
1407
+ rparen: p.child("rparen"),
1408
+ over: p.child("over", (x) => [" ", x], "all"),
1409
+ as: "",
1410
+ alias: printAlias(path, options, print, node),
1411
+ order: printOrder(path, options, print, node),
1412
+ null_order: "",
1413
+ comma: printComma(path, options, print, node),
1414
+ };
1415
+ // TODO
1416
+ // check if parse order is collect
1417
+ // this block shold be placed before RESPECT/IGNORE?
1418
+ const trailings = [
1419
+ docs.ignore_nulls,
1420
+ docs.orderby,
1421
+ docs.limit,
1422
+ docs.having,
1423
+ ].filter((x) => x !== "");
1424
+ let noNewLine = !p.has("distinct") &&
1425
+ p.len("args") <= 1 &&
1426
+ !p.hasLeadingComments("args") &&
1427
+ trailings.length === 0 &&
1428
+ !p.hasLeadingComments("rparen")
1429
+ ? true
1430
+ : false;
1431
+ if (p.children.args &&
1432
+ !["GroupedExpr", "GroupedStatement", "CallingFunction"].includes(
1433
+ // TODO the same array appears in printAssertStatement. DRY!
1434
+ p.children.args.NodeVec[0].node_type)) {
1435
+ noNewLine = false;
1436
+ }
1437
+ const insideParen = [
1438
+ noNewLine ? "" : softline,
1439
+ docs.distinct,
1440
+ docs.args,
1441
+ trailings.map((x) => [line, group(x)]),
1442
+ ];
1443
+ return [
1444
+ // func often has leading_comments, so it is placed out of group
1445
+ docs.func,
1446
+ group([
1447
+ docs.self,
1448
+ docs.trailing_comments,
1449
+ noNewLine ? insideParen : indent(insideParen),
1450
+ noNewLine ? "" : softline,
1451
+ docs.rparen,
1452
+ ]),
1453
+ docs.over,
1454
+ docs.alias,
1455
+ docs.order,
1456
+ docs.comma,
1457
+ ];
1458
+ };
1459
+ const printCallingTableFunction = (path, options, print, node) => {
1460
+ const docs = {
1461
+ self: printCallingFunctionGeneral(path, options, print, node),
1462
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
1463
+ unpivot: "",
1464
+ /* eslint-disable unicorn/no-unused-properties */
1465
+ leading_comments: "",
1466
+ func: "",
1467
+ trailing_comments: "",
1468
+ args: "",
1469
+ rparen: "",
1470
+ as: "",
1471
+ alias: "",
1472
+ /* eslint-enable unicorn/no-unused-properties */
1473
+ };
1474
+ return [docs.self, docs.pivot];
1475
+ };
1476
+ const printCallingUnnest = (path, options, print, node) => {
1477
+ const p = new Printer(path, options, print, node);
1478
+ const docs = {
1479
+ self: printCallingFunctionGeneral(path, options, print, node),
1480
+ with_offset: p.child("with_offset", (x) => group([line, x])),
1481
+ offset_as: p.child("offset_as", undefined, "all"),
1482
+ offset_alias: p.child("offset_alias", undefined, "all"),
1483
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
1484
+ unpivot: "",
1485
+ /* eslint-disable unicorn/no-unused-properties */
1486
+ leading_comments: "",
1487
+ func: "",
1488
+ trailing_comments: "",
1489
+ args: "",
1490
+ rparen: "",
1491
+ as: "",
1492
+ alias: "",
1493
+ /* eslint-enable unicorn/no-unused-properties */
1494
+ };
1495
+ return [
1496
+ docs.self,
1497
+ docs.with_offset,
1498
+ p.has("offset_alias")
1499
+ ? [
1500
+ " ",
1501
+ docs.offset_as || (options.printKeywordsInUpperCase ? "AS" : "as"),
1502
+ ]
1503
+ : "",
1504
+ p.has("offset_alias") ? [" ", docs.offset_alias] : "",
1505
+ docs.pivot,
1506
+ ];
1507
+ };
1508
+ const printCallStatement = (path, options, print, node) => {
1509
+ const p = new Printer(path, options, print, node);
1510
+ const docs = {
1511
+ leading_comments: printLeadingComments(path, options, print, node),
1512
+ self: p.self("upper"),
1513
+ trailing_comments: printTrailingComments(path, options, print, node),
1514
+ procedure: p.child("procedure", undefined, "all"),
1515
+ semicolon: p.child("semicolon"),
1516
+ };
1517
+ return [
1518
+ docs.leading_comments,
1519
+ group([
1520
+ docs.self,
1521
+ docs.trailing_comments,
1522
+ " ",
1523
+ docs.procedure,
1524
+ softline,
1525
+ docs.semicolon,
1526
+ ]),
1527
+ p.newLine(),
1528
+ ];
1529
+ };
1530
+ const printCaseExpr = (path, options, print, node) => {
1531
+ const p = new Printer(path, options, print, node);
1532
+ const docs = {
1533
+ leading_comments: printLeadingComments(path, options, print, node),
1534
+ self: p.self(),
1535
+ trailing_comments: printTrailingComments(path, options, print, node),
1536
+ expr: p.child("expr", undefined, "all"),
1537
+ arms: p.child("arms", (x) => [line, group(x)], "none"),
1538
+ end: p.child("end", undefined, "all"),
1539
+ as: "",
1540
+ alias: printAlias(path, options, print, node),
1541
+ order: printOrder(path, options, print, node),
1542
+ null_order: "",
1543
+ comma: printComma(path, options, print, node),
1544
+ };
1545
+ let res = [
1546
+ docs.self,
1547
+ docs.trailing_comments,
1548
+ p.has("expr") ? " " : "",
1549
+ docs.expr,
1550
+ indent(docs.arms),
1551
+ " ",
1552
+ docs.end,
1553
+ ];
1554
+ if (p.len("arms") <= 2) {
1555
+ res = group(res);
1556
+ }
1557
+ return [docs.leading_comments, res, docs.alias, docs.order, docs.comma];
1558
+ };
1559
+ const printCaseExprArm = (path, options, print, node) => {
1560
+ const p = new Printer(path, options, print, node);
1561
+ const docs = {
1562
+ leading_comments: printLeadingComments(path, options, print, node),
1563
+ self: p.self(),
1564
+ trailing_comments: printTrailingComments(path, options, print, node),
1565
+ expr: p.child("expr", undefined, "all"),
1566
+ then: p.child("then", undefined),
1567
+ result: p.child("result"),
1568
+ };
1569
+ return [
1570
+ docs.leading_comments,
1571
+ docs.self,
1572
+ docs.trailing_comments,
1573
+ group([indent([p.has("expr") ? line : "", docs.expr])]),
1574
+ indent([p.has("then") ? line : "", group([docs.then, " ", docs.result])]),
1575
+ ];
1576
+ };
1577
+ const printCastArgument = (path, options, print, node) => {
1578
+ const p = new Printer(path, options, print, node);
1579
+ const docs = {
1580
+ leading_comments: "",
1581
+ cast_from: p.child("cast_from"),
1582
+ self: p.self("upper", true),
1583
+ trailing_comments: printTrailingComments(path, options, print, node),
1584
+ cast_to: p.child("cast_to", undefined, "all"),
1585
+ format: p.child("format", undefined, "all"),
1586
+ };
1587
+ return [
1588
+ docs.cast_from,
1589
+ " ",
1590
+ docs.self,
1591
+ docs.trailing_comments,
1592
+ " ",
1593
+ docs.cast_to,
1594
+ p.has("format") ? " " : "",
1595
+ docs.format,
1596
+ ];
1597
+ };
1598
+ const printComment = (path, options, print, node) => {
1599
+ const p = new Printer(path, options, print, node);
1600
+ const token = p.node.token;
1601
+ const splittedComment = token.literal.split("\n").map((x) => x.trim());
1602
+ if (options.formatMultilineComment && 2 <= splittedComment.length) {
1603
+ const formattedRows = [];
1604
+ const firstRow = splittedComment.shift();
1605
+ if (firstRow && 3 <= firstRow.length) {
1606
+ formattedRows.push(firstRow.slice(0, 2));
1607
+ formattedRows.push(" * " + firstRow.slice(2).trim());
1608
+ }
1609
+ else {
1610
+ formattedRows.push(firstRow);
1611
+ }
1612
+ const lastRow = splittedComment.pop();
1613
+ for (const row of splittedComment) {
1614
+ if (row.startsWith("*")) {
1615
+ formattedRows.push(" " + row);
1616
+ }
1617
+ else {
1618
+ formattedRows.push(" * " + row);
1619
+ }
1620
+ }
1621
+ if (lastRow && 3 <= lastRow.length) {
1622
+ const lastRowHead = lastRow.slice(0, -2).trim();
1623
+ if (lastRowHead.startsWith("*")) {
1624
+ formattedRows.push(" " + lastRowHead);
1625
+ }
1626
+ else {
1627
+ formattedRows.push(" * " + lastRowHead);
1628
+ }
1629
+ formattedRows.push(" " + lastRow.slice(-2));
1630
+ }
1631
+ else {
1632
+ formattedRows.push(" " + lastRow.slice(-2)); // eslint-disable-line @typescript-eslint/no-non-null-assertion
1633
+ }
1634
+ token.literal = formattedRows.join("\n");
1635
+ }
1636
+ const docs = {
1637
+ self: p.self(),
1638
+ };
1639
+ return docs.self;
1640
+ };
1641
+ const printConstraint = (path, options, print, node) => {
1642
+ const p = new Printer(path, options, print, node);
1643
+ const docs = {
1644
+ constraint: p.child("constraint", undefined, "all"),
1645
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x]), "all"),
1646
+ ident: p.child("ident", undefined, "all"),
1647
+ leading_comments: "",
1648
+ self: p.self("upper", true),
1649
+ trailing_comments: printTrailingComments(path, options, print, node),
1650
+ key: p.child("key", undefined, "all"),
1651
+ columns: p.child("columns", undefined, "all"),
1652
+ references: p.child("references", undefined, "all"),
1653
+ enforced: p.child("enforced", undefined, "all"),
1654
+ comma: p.child("comma", undefined, "all"),
1655
+ };
1656
+ return [
1657
+ docs.constraint,
1658
+ docs.if_not_exists,
1659
+ p.has("ident") ? " " : "",
1660
+ docs.ident,
1661
+ p.has("ident") ? " " : "",
1662
+ docs.self,
1663
+ docs.trailing_comments,
1664
+ " ",
1665
+ docs.key,
1666
+ docs.columns,
1667
+ p.has("references") ? " " : "",
1668
+ docs.references,
1669
+ p.has("enforced") ? " " : "",
1670
+ docs.enforced,
1671
+ docs.comma,
1672
+ ];
1673
+ };
1674
+ const printCreateFunctionStatement = (path, options, print, node) => {
1675
+ const p = new Printer(path, options, print, node);
1676
+ p.setLiteral("temp", options.printKeywordsInUpperCase ? "TEMP" : "temp");
1677
+ const docs = {
1678
+ leading_comments: printLeadingComments(path, options, print, node),
1679
+ self: p.self("upper"),
1680
+ trailing_comments: printTrailingComments(path, options, print, node),
1681
+ or_replace: p.child("or_replace", (x) => group([line, x])),
1682
+ temp: p.child("temp", undefined, "all"),
1683
+ table: p.child("table", undefined, "all"),
1684
+ what: p.child("what", undefined, "all"),
1685
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1686
+ ident: p.child("ident", undefined, "all"),
1687
+ group: p.child("group", undefined, "all"),
1688
+ returns: p.child("returns"),
1689
+ remote: p.child("remote"),
1690
+ determinism: group(p.child("determinism", undefined, "none", line)),
1691
+ language: p.child("language"),
1692
+ options: p.child("options"),
1693
+ as: p.child("as"),
1694
+ semicolon: p.child("semicolon"),
1695
+ };
1696
+ return [
1697
+ docs.leading_comments,
1698
+ group([
1699
+ group([
1700
+ docs.self,
1701
+ docs.trailing_comments,
1702
+ docs.or_replace,
1703
+ p.has("temp") ? " " : "",
1704
+ docs.temp,
1705
+ p.has("table") ? " " : "",
1706
+ docs.table,
1707
+ " ",
1708
+ docs.what,
1709
+ docs.if_not_exists,
1710
+ " ",
1711
+ docs.ident,
1712
+ docs.group,
1713
+ ]),
1714
+ p.has("returns") ? line : "",
1715
+ docs.returns,
1716
+ p.has("remote") ? line : "",
1717
+ docs.remote,
1718
+ p.has("determinism") ? line : "",
1719
+ docs.determinism,
1720
+ p.has("language") ? line : "",
1721
+ docs.language,
1722
+ p.has("options") ? line : "",
1723
+ docs.options,
1724
+ p.has("as") ? line : "",
1725
+ docs.as,
1726
+ softline,
1727
+ docs.semicolon,
1728
+ ]),
1729
+ p.newLine(),
1730
+ ];
1731
+ };
1732
+ const printCreateProcedureStatement = (path, options, print, node) => {
1733
+ const p = new Printer(path, options, print, node);
1734
+ p.setNotRoot("stmt");
1735
+ const docs = {
1736
+ leading_comments: printLeadingComments(path, options, print, node),
1737
+ self: p.self("upper"),
1738
+ trailing_comments: printTrailingComments(path, options, print, node),
1739
+ or_replace: p.child("or_replace", (x) => group([line, x])),
1740
+ what: p.child("what", undefined, "all"),
1741
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1742
+ ident: p.child("ident", undefined, "all"),
1743
+ group: p.child("group", undefined, "all"),
1744
+ with_connection: p.child("with_connection"),
1745
+ options: p.child("options"),
1746
+ language: p.child("language"),
1747
+ stmt: p.child("stmt"),
1748
+ as: p.child("as"),
1749
+ semicolon: p.child("semicolon"),
1750
+ };
1751
+ return [
1752
+ docs.leading_comments,
1753
+ group([
1754
+ group([
1755
+ docs.self,
1756
+ docs.trailing_comments,
1757
+ docs.or_replace,
1758
+ " ",
1759
+ docs.what,
1760
+ docs.if_not_exists,
1761
+ " ",
1762
+ docs.ident,
1763
+ docs.group,
1764
+ ]),
1765
+ p.has("with_connection") ? line : "",
1766
+ docs.with_connection,
1767
+ p.has("options") ? line : "",
1768
+ docs.options,
1769
+ p.has("language") ? line : "",
1770
+ docs.language,
1771
+ p.has("stmt") ? line : "",
1772
+ docs.stmt,
1773
+ p.has("as") ? line : "",
1774
+ docs.as,
1775
+ softline,
1776
+ docs.semicolon,
1777
+ ]),
1778
+ p.newLine(),
1779
+ ];
1780
+ };
1781
+ const printCreateReservationStatement = (path, options, print, node) => {
1782
+ const p = new Printer(path, options, print, node);
1783
+ const docs = {
1784
+ leading_comments: printLeadingComments(path, options, print, node),
1785
+ self: p.self("upper"),
1786
+ trailing_comments: printTrailingComments(path, options, print, node),
1787
+ what: p.child("what", undefined, "all"),
1788
+ ident: p.child("ident", undefined, "all"),
1789
+ as: p.child("as"),
1790
+ json: p.child("json", undefined, "all"),
1791
+ json_string: p.child("json_string", undefined, "all"),
1792
+ options: p.child("options", undefined, "all"),
1793
+ semicolon: p.child("semicolon"),
1794
+ };
1795
+ return [
1796
+ docs.leading_comments,
1797
+ group([
1798
+ docs.self,
1799
+ docs.trailing_comments,
1800
+ " ",
1801
+ docs.what,
1802
+ " ",
1803
+ docs.ident,
1804
+ line,
1805
+ docs.as,
1806
+ p.has("json") ? " " : "",
1807
+ docs.json,
1808
+ p.has("json_string") ? " " : "",
1809
+ docs.json_string,
1810
+ docs.options,
1811
+ softline,
1812
+ docs.semicolon,
1813
+ ]),
1814
+ p.newLine(),
1815
+ ];
1816
+ };
1817
+ const printCreateRowAccessPolicyStatement = (path, options, print, node) => {
1818
+ const p = new Printer(path, options, print, node);
1819
+ const docs = {
1820
+ leading_comments: printLeadingComments(path, options, print, node),
1821
+ self: p.self("upper"),
1822
+ trailing_comments: printTrailingComments(path, options, print, node),
1823
+ or_replace: p.child("or_replace", (x) => group([line, x])),
1824
+ what: p.child("what", undefined, "all", " "),
1825
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1826
+ ident: p.child("ident", undefined, "all"),
1827
+ on: p.child("on"),
1828
+ grant: p.child("grant"),
1829
+ to: p.child("to", undefined, "all"),
1830
+ filter: p.child("filter"),
1831
+ using: p.child("using", undefined, "all"),
1832
+ semicolon: p.child("semicolon"),
1833
+ };
1834
+ return [
1835
+ docs.leading_comments,
1836
+ group([
1837
+ docs.self,
1838
+ docs.trailing_comments,
1839
+ docs.or_replace,
1840
+ " ",
1841
+ docs.what,
1842
+ docs.if_not_exists,
1843
+ " ",
1844
+ docs.ident,
1845
+ line,
1846
+ docs.on,
1847
+ p.has("grant") ? line : "",
1848
+ docs.grant,
1849
+ p.has("to") ? " " : "",
1850
+ docs.to,
1851
+ line,
1852
+ docs.filter,
1853
+ " ",
1854
+ docs.using,
1855
+ softline,
1856
+ docs.semicolon,
1857
+ ]),
1858
+ p.newLine(),
1859
+ ];
1860
+ };
1861
+ const printCreateSchemaStatement = (path, options, print, node) => {
1862
+ const p = new Printer(path, options, print, node);
1863
+ const docs = {
1864
+ leading_comments: printLeadingComments(path, options, print, node),
1865
+ self: p.self("upper"),
1866
+ trailing_comments: printTrailingComments(path, options, print, node),
1867
+ what: p.child("what", undefined, "all"),
1868
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1869
+ ident: p.child("ident", undefined, "all"),
1870
+ default_collate: p.child("default_collate"),
1871
+ options: p.child("options"),
1872
+ semicolon: p.child("semicolon"),
1873
+ };
1874
+ return [
1875
+ docs.leading_comments,
1876
+ group([
1877
+ docs.self,
1878
+ docs.trailing_comments,
1879
+ " ",
1880
+ docs.what,
1881
+ docs.if_not_exists,
1882
+ " ",
1883
+ docs.ident,
1884
+ p.has("default_collate") ? line : "",
1885
+ docs.default_collate,
1886
+ p.has("options") ? line : "",
1887
+ docs.options,
1888
+ softline,
1889
+ docs.semicolon,
1890
+ ]),
1891
+ p.newLine(),
1892
+ ];
1893
+ };
1894
+ const printCreateSearchIndexStatement = (path, options, print, node) => {
1895
+ const p = new Printer(path, options, print, node);
1896
+ const docs = {
1897
+ leading_comments: printLeadingComments(path, options, print, node),
1898
+ self: p.self("upper"),
1899
+ trailing_comments: printTrailingComments(path, options, print, node),
1900
+ what: p.child("what", undefined, "all"),
1901
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1902
+ ident: p.child("ident", undefined, "all"),
1903
+ on: p.child("on"),
1904
+ tablename: p.child("tablename", undefined, "all"),
1905
+ column_group: p.child("column_group", undefined, "all"),
1906
+ options: p.child("options"),
1907
+ semicolon: p.child("semicolon"),
1908
+ };
1909
+ return [
1910
+ docs.leading_comments,
1911
+ group([
1912
+ docs.self,
1913
+ docs.trailing_comments,
1914
+ " ",
1915
+ docs.what,
1916
+ docs.if_not_exists,
1917
+ " ",
1918
+ docs.ident,
1919
+ line,
1920
+ docs.on,
1921
+ " ",
1922
+ docs.tablename,
1923
+ " ",
1924
+ docs.column_group,
1925
+ p.has("options") ? line : "",
1926
+ docs.options,
1927
+ softline,
1928
+ docs.semicolon,
1929
+ ]),
1930
+ p.newLine(),
1931
+ ];
1932
+ };
1933
+ const printCreateTableStatement = (path, options, print, node) => {
1934
+ const p = new Printer(path, options, print, node);
1935
+ p.setLiteral("temp", "TEMP");
1936
+ const docs = {
1937
+ leading_comments: printLeadingComments(path, options, print, node),
1938
+ self: p.self("upper"),
1939
+ trailing_comments: printTrailingComments(path, options, print, node),
1940
+ or_replace: p.child("or_replace", (x) => group([line, x])),
1941
+ temp: p.child("temp", undefined, "all"),
1942
+ external: p.child("external", undefined, "all"),
1943
+ snapshot: p.child("snapshot", undefined, "all"),
1944
+ what: p.child("what", undefined, "all"),
1945
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
1946
+ ident: p.child("ident", undefined, "all"),
1947
+ like_or_copy: p.child("like_or_copy"),
1948
+ source_table: p.child("source_table", undefined, "all"),
1949
+ column_schema_group: p.child("column_schema_group", undefined, "all"),
1950
+ default_collate: p.child("default_collate"),
1951
+ partitionby: p.child("partitionby"),
1952
+ clusterby: p.child("clusterby"),
1953
+ with_connection: p.child("with_connection"),
1954
+ with_partition_columns: p.child("with_partition_columns"),
1955
+ clone: p.child("clone"),
1956
+ options: p.child("options"),
1957
+ as: p.child("as", undefined, "all"),
1958
+ semicolon: p.child("semicolon"),
1959
+ };
1960
+ return [
1961
+ docs.leading_comments,
1962
+ group([
1963
+ docs.self,
1964
+ docs.trailing_comments,
1965
+ docs.or_replace,
1966
+ p.has("temp") ? " " : "",
1967
+ docs.temp,
1968
+ p.has("external") ? " " : "",
1969
+ docs.external,
1970
+ p.has("snapshot") ? " " : "",
1971
+ docs.snapshot,
1972
+ " ",
1973
+ docs.what,
1974
+ docs.if_not_exists,
1975
+ " ",
1976
+ docs.ident,
1977
+ p.has("like_or_copy") ? " " : "",
1978
+ docs.like_or_copy,
1979
+ p.has("source_table") ? " " : "",
1980
+ docs.source_table,
1981
+ p.has("column_schema_group") ? " " : "",
1982
+ docs.column_schema_group,
1983
+ p.has("default_collate") ? line : "",
1984
+ docs.default_collate,
1985
+ p.has("partitionby") ? line : "",
1986
+ docs.partitionby,
1987
+ p.has("clusterby") ? line : "",
1988
+ docs.clusterby,
1989
+ p.has("with_connection") ? line : "",
1990
+ docs.with_connection,
1991
+ p.has("with_partition_columns") ? line : "",
1992
+ docs.with_partition_columns,
1993
+ p.has("clone") ? line : "",
1994
+ docs.clone,
1995
+ p.has("options") ? line : "",
1996
+ docs.options,
1997
+ p.has("as") ? line : "",
1998
+ docs.as,
1999
+ softline,
2000
+ docs.semicolon,
2001
+ ]),
2002
+ p.newLine(),
2003
+ ];
2004
+ };
2005
+ const printCreateViewStatement = (path, options, print, node) => {
2006
+ const p = new Printer(path, options, print, node);
2007
+ const docs = {
2008
+ leading_comments: printLeadingComments(path, options, print, node),
2009
+ self: p.self("upper"),
2010
+ trailing_comments: printTrailingComments(path, options, print, node),
2011
+ or_replace: p.child("or_replace", (x) => group([line, x])),
2012
+ materialized: p.child("materialized", undefined, "all"),
2013
+ what: p.child("what", undefined, "all"),
2014
+ if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
2015
+ ident: p.child("ident", undefined, "all"),
2016
+ column_name_list: p.child("column_name_list", undefined, "all"),
2017
+ partitionby: p.child("partitionby"),
2018
+ clusterby: p.child("clusterby"),
2019
+ options: p.child("options"),
2020
+ as: p.child("as", undefined, "all"),
2021
+ semicolon: p.child("semicolon"),
2022
+ };
2023
+ return [
2024
+ docs.leading_comments,
2025
+ group([
2026
+ docs.self,
2027
+ docs.trailing_comments,
2028
+ docs.or_replace,
2029
+ p.has("materialized") ? " " : "",
2030
+ docs.materialized,
2031
+ " ",
2032
+ docs.what,
2033
+ docs.if_not_exists,
2034
+ " ",
2035
+ docs.ident,
2036
+ p.has("column_name_list") ? " " : "",
2037
+ docs.column_name_list,
2038
+ p.has("partitionby") ? line : "",
2039
+ docs.partitionby,
2040
+ p.has("clusterby") ? line : "",
2041
+ docs.clusterby,
2042
+ p.has("options") ? line : "",
2043
+ docs.options,
2044
+ line,
2045
+ docs.as,
2046
+ softline,
2047
+ docs.semicolon,
2048
+ ]),
2049
+ p.newLine(),
2050
+ ];
2051
+ };
2052
+ const printDeclareStatement = (path, options, print, node) => {
2053
+ const p = new Printer(path, options, print, node);
2054
+ const docs = {
2055
+ leading_comments: printLeadingComments(path, options, print, node),
2056
+ self: p.self("upper"),
2057
+ trailing_comments: printTrailingComments(path, options, print, node),
2058
+ idents: p.child("idents", (x) => [line, x]),
2059
+ variable_type: p.child("variable_type"),
2060
+ default: p.child("default"),
2061
+ semicolon: p.child("semicolon"),
2062
+ };
2063
+ return [
2064
+ docs.leading_comments,
2065
+ group([
2066
+ docs.self,
2067
+ docs.trailing_comments,
2068
+ indent(docs.idents),
2069
+ p.has("variable_type") ? line : "",
2070
+ docs.variable_type,
2071
+ p.has("default") ? line : "",
2072
+ docs.default,
2073
+ softline,
2074
+ docs.semicolon,
2075
+ ]),
2076
+ p.newLine(),
2077
+ ];
2078
+ };
2079
+ const printDeleteStatement = (path, options, print, node) => {
2080
+ const p = new Printer(path, options, print, node);
2081
+ const docs = {
2082
+ leading_comments: printLeadingComments(path, options, print, node),
2083
+ self: p.self("upper"),
2084
+ trailing_comments: printTrailingComments(path, options, print, node),
2085
+ from: p.consumeAllCommentsOfX("from"),
2086
+ table_name: p.child("table_name", undefined, "all"),
2087
+ where: p.child("where"),
2088
+ semicolon: p.child("semicolon"),
2089
+ };
2090
+ return [
2091
+ docs.leading_comments,
2092
+ group([
2093
+ docs.self,
2094
+ docs.trailing_comments,
2095
+ docs.from,
2096
+ " ",
2097
+ docs.table_name,
2098
+ line,
2099
+ docs.where,
2100
+ softline,
2101
+ docs.semicolon,
2102
+ ]),
2103
+ p.newLine(),
2104
+ ];
2105
+ };
2106
+ const printDifferentialPrivacyClause = (path, options, print, node) => {
2107
+ const p = new Printer(path, options, print, node);
2108
+ const docs = {
2109
+ leading_comments: printLeadingComments(path, options, print, node),
2110
+ self: p.self("upper"),
2111
+ trailing_comments: printTrailingComments(path, options, print, node),
2112
+ differential_privacy: p.child("differential_privacy"),
2113
+ options: p.child("options"),
2114
+ };
2115
+ return [
2116
+ docs.leading_comments,
2117
+ group([
2118
+ docs.self,
2119
+ docs.trailing_comments,
2120
+ " ",
2121
+ docs.differential_privacy,
2122
+ p.has("options") ? " " : "",
2123
+ docs.options,
2124
+ ]),
2125
+ ];
2126
+ };
2127
+ const printDotOperator = (path, options, print, node) => {
2128
+ const p = new Printer(path, options, print, node);
2129
+ p.setNotGlobal("right");
2130
+ const docs = {
2131
+ leading_comments: "",
2132
+ left: p.child("left"),
2133
+ self: p.self("upper", true),
2134
+ trailing_comments: printTrailingComments(path, options, print, node),
2135
+ right: p.child("right", undefined, "all"),
2136
+ as: "",
2137
+ alias: printAlias(path, options, print, node),
2138
+ for_system_time_as_of: p.child("for_system_time_as_of", undefined, "all"),
2139
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
2140
+ unpivot: "",
2141
+ tablesample: p.child("tablesample", undefined, "all"),
2142
+ order: printOrder(path, options, print, node),
2143
+ null_order: "",
2144
+ comma: printComma(path, options, print, node),
2145
+ };
2146
+ return [
2147
+ docs.left,
2148
+ docs.self,
2149
+ docs.trailing_comments,
2150
+ docs.right,
2151
+ docs.alias,
2152
+ p.has("for_system_time_as_of") ? [" ", docs.for_system_time_as_of] : "",
2153
+ docs.pivot,
2154
+ p.has("tablesample") ? [" ", docs.tablesample] : "",
2155
+ docs.order,
2156
+ docs.comma,
2157
+ ];
2158
+ };
2159
+ const printDropRowAccessPolicyStatement = (path, options, print, node) => {
2160
+ const p = new Printer(path, options, print, node);
2161
+ const docs = {
2162
+ leading_comments: printLeadingComments(path, options, print, node),
2163
+ self: p.self("upper"),
2164
+ trailing_comments: printTrailingComments(path, options, print, node),
2165
+ what: p.child("what", undefined, "all", " "),
2166
+ if_exists: p.child("if_exists", (x) => group([line, x])),
2167
+ ident: p.child("ident", undefined, "all"),
2168
+ on: p.child("on"),
2169
+ semicolon: p.child("semicolon"),
2170
+ };
2171
+ return [
2172
+ docs.leading_comments,
2173
+ group([
2174
+ docs.self,
2175
+ docs.trailing_comments,
2176
+ " ",
2177
+ docs.what,
2178
+ docs.if_exists,
2179
+ p.has("ident") ? " " : "",
2180
+ docs.ident,
2181
+ line,
2182
+ docs.on,
2183
+ softline,
2184
+ docs.semicolon,
2185
+ ]),
2186
+ p.newLine(),
2187
+ ];
2188
+ };
2189
+ const printDropStatement = (path, options, print, node) => {
2190
+ const p = new Printer(path, options, print, node);
2191
+ const docs = {
2192
+ leading_comments: printLeadingComments(path, options, print, node),
2193
+ self: p.self("upper"),
2194
+ trailing_comments: printTrailingComments(path, options, print, node),
2195
+ external: p.child("external", undefined, "all"),
2196
+ table: p.child("table", undefined, "all"),
2197
+ materialized: p.child("materialized", undefined, "all"),
2198
+ what: p.child("what", undefined, "all"),
2199
+ if_exists: p.child("if_exists", (x) => group([line, x])),
2200
+ ident: p.child("ident", undefined, "all"),
2201
+ on: p.child("on"),
2202
+ cascade_or_restrict: p.child("cascade_or_restrict", undefined, "all"),
2203
+ semicolon: p.child("semicolon"),
2204
+ };
2205
+ return [
2206
+ docs.leading_comments,
2207
+ group([
2208
+ docs.self,
2209
+ docs.trailing_comments,
2210
+ p.has("external") ? " " : "",
2211
+ docs.external,
2212
+ p.has("materialized") ? " " : "",
2213
+ docs.materialized,
2214
+ p.has("table") ? " " : "",
2215
+ docs.table,
2216
+ " ",
2217
+ docs.what,
2218
+ docs.if_exists,
2219
+ " ",
2220
+ docs.ident,
2221
+ p.has("on") ? line : "",
2222
+ docs.on,
2223
+ p.has("cascade_or_restrict") ? " " : "",
2224
+ docs.cascade_or_restrict,
2225
+ softline,
2226
+ docs.semicolon,
2227
+ ]),
2228
+ p.newLine(),
2229
+ ];
2230
+ };
2231
+ const printElseIfClause = (path, options, print, node) => {
2232
+ const p = new Printer(path, options, print, node);
2233
+ const docs = {
2234
+ leading_comments: printLeadingComments(path, options, print, node),
2235
+ self: p.self("upper"),
2236
+ trailing_comments: printTrailingComments(path, options, print, node),
2237
+ condition: p.child("condition", undefined, "all"),
2238
+ then: p.child("then", undefined, "all"),
2239
+ };
2240
+ return [
2241
+ docs.leading_comments,
2242
+ docs.self,
2243
+ docs.trailing_comments,
2244
+ " ",
2245
+ docs.condition,
2246
+ " ",
2247
+ docs.then,
2248
+ ];
2249
+ };
2250
+ const printEOF = (path, options, print, node) => {
2251
+ const docs = {
2252
+ leading_comments: printLeadingComments(path, options, print, node),
2253
+ self: "", // eslint-disable-line unicorn/no-unused-properties
2254
+ };
2255
+ return docs.leading_comments;
2256
+ };
2257
+ const printExecuteStatement = (path, options, print, node) => {
2258
+ const p = new Printer(path, options, print, node);
2259
+ const docs = {
2260
+ leading_comments: printLeadingComments(path, options, print, node),
2261
+ self: p.self("upper"),
2262
+ trailing_comments: printTrailingComments(path, options, print, node),
2263
+ immediate: p.child("immediate", undefined, "all"),
2264
+ sql_expr: p.child("sql_expr", undefined, "all"),
2265
+ into: p.child("into"),
2266
+ using: p.child("using"),
2267
+ semicolon: p.child("semicolon"),
2268
+ };
2269
+ return [
2270
+ docs.leading_comments,
2271
+ group([
2272
+ docs.self,
2273
+ docs.trailing_comments,
2274
+ " ",
2275
+ docs.immediate,
2276
+ " ",
2277
+ docs.sql_expr,
2278
+ p.has("into") ? line : "",
2279
+ docs.into,
2280
+ p.has("using") ? line : "",
2281
+ docs.using,
2282
+ softline,
2283
+ docs.semicolon,
2284
+ ]),
2285
+ p.newLine(),
2286
+ ];
2287
+ };
2288
+ const printExportStatement = (path, options, print, node) => {
2289
+ const p = new Printer(path, options, print, node);
2290
+ const docs = {
2291
+ leading_comments: printLeadingComments(path, options, print, node),
2292
+ self: p.self("upper"),
2293
+ trailing_comments: printTrailingComments(path, options, print, node),
2294
+ data: p.child("data", undefined, "all"),
2295
+ options: p.child("options"),
2296
+ as: p.child("as"),
2297
+ semicolon: p.child("semicolon"),
2298
+ };
2299
+ return [
2300
+ docs.leading_comments,
2301
+ group([
2302
+ docs.self,
2303
+ docs.trailing_comments,
2304
+ " ",
2305
+ docs.data,
2306
+ line,
2307
+ docs.options,
2308
+ line,
2309
+ docs.as,
2310
+ softline,
2311
+ docs.semicolon,
2312
+ ]),
2313
+ p.newLine(),
2314
+ ];
2315
+ };
2316
+ const printExtractArgument = (path, options, print, node) => {
2317
+ const p = new Printer(path, options, print, node);
2318
+ node.children.extract_datepart.Node.isDatePart = true;
2319
+ const docs = {
2320
+ leading_comments: "",
2321
+ extract_datepart: p.child("extract_datepart"),
2322
+ self: p.self("upper", true),
2323
+ trailing_comments: printTrailingComments(path, options, print, node),
2324
+ extract_from: p.child("extract_from", undefined, "all"),
2325
+ at_time_zone: p.child("at_time_zone", undefined, "all", " "),
2326
+ time_zone: p.child("time_zone", undefined, "all"),
2327
+ };
2328
+ return [
2329
+ docs.extract_datepart,
2330
+ " ",
2331
+ docs.self,
2332
+ docs.trailing_comments,
2333
+ " ",
2334
+ docs.extract_from,
2335
+ p.has("at_time_zone") ? line : "",
2336
+ docs.at_time_zone,
2337
+ p.has("time_zone") ? " " : "",
2338
+ docs.time_zone,
2339
+ ];
2340
+ };
2341
+ const printForStatement = (path, options, print, node) => {
2342
+ const p = new Printer(path, options, print, node);
2343
+ let leading_label_comments = "";
2344
+ if (node.children.leading_label &&
2345
+ node.children.leading_label.Node.children.leading_comments) {
2346
+ leading_label_comments =
2347
+ node.children.leading_label.Node.children.leading_comments.NodeVec.map((n) => [n.token.literal, hardline]);
2348
+ p.consumeLeadingCommentsOfX("leading_label");
2349
+ }
2350
+ const docs = {
2351
+ leading_label: p.child("leading_label"),
2352
+ colon: p.child("colon", undefined, "all"),
2353
+ leading_comments: printLeadingComments(path, options, print, node),
2354
+ self: p.self("upper"),
2355
+ trailing_comments: printTrailingComments(path, options, print, node),
2356
+ ident: p.child("ident", undefined, "all"),
2357
+ in: p.child("in", undefined, "all"),
2358
+ do: p.child("do", undefined, "all"),
2359
+ end_for: group(p.child("end_for", undefined, "none", line)),
2360
+ trailing_label: p.child("trailing_label", undefined, "all"),
2361
+ semicolon: p.child("semicolon"),
2362
+ };
2363
+ return [
2364
+ leading_label_comments,
2365
+ docs.leading_comments,
2366
+ group([
2367
+ group([
2368
+ docs.leading_label,
2369
+ docs.colon,
2370
+ p.has("leading_label") ? " " : "",
2371
+ docs.self,
2372
+ docs.trailing_comments,
2373
+ " ",
2374
+ docs.ident,
2375
+ " ",
2376
+ docs.in,
2377
+ ]),
2378
+ " ",
2379
+ docs.do,
2380
+ line,
2381
+ docs.end_for,
2382
+ p.has("trailing_label") ? " " : "",
2383
+ docs.trailing_label,
2384
+ softline,
2385
+ docs.semicolon,
2386
+ ]),
2387
+ p.newLine(),
2388
+ ];
2389
+ };
2390
+ const printForSystemTimeAsOfclause = (path, options, print, node) => {
2391
+ const p = new Printer(path, options, print, node);
2392
+ const docs = {
2393
+ leading_comments: printLeadingComments(path, options, print, node),
2394
+ self: p.self("upper"),
2395
+ trailing_comments: printTrailingComments(path, options, print, node),
2396
+ system_time_as_of: p.child("system_time_as_of", (x) => group([line, x])),
2397
+ expr: p.child("expr", undefined, "all"),
2398
+ };
2399
+ return [
2400
+ docs.leading_comments,
2401
+ docs.self,
2402
+ docs.trailing_comments,
2403
+ docs.system_time_as_of,
2404
+ " ",
2405
+ docs.expr,
2406
+ ];
2407
+ };
2408
+ const printGrantStatement = (path, options, print, node) => {
2409
+ const p = new Printer(path, options, print, node);
2410
+ const docs = {
2411
+ leading_comments: printLeadingComments(path, options, print, node),
2412
+ self: p.self("upper"),
2413
+ trailing_comments: printTrailingComments(path, options, print, node),
2414
+ roles: p.child("roles", (x) => [line, x]),
2415
+ on: p.child("on"),
2416
+ resource_type: p.child("resource_type", undefined, "all"),
2417
+ ident: p.child("ident", undefined, "all"),
2418
+ to: p.child("to"),
2419
+ semicolon: p.child("semicolon"),
2420
+ };
2421
+ return [
2422
+ docs.leading_comments,
2423
+ group([
2424
+ group([docs.self, docs.trailing_comments, docs.roles]),
2425
+ line,
2426
+ docs.on,
2427
+ " ",
2428
+ docs.resource_type,
2429
+ " ",
2430
+ docs.ident,
2431
+ line,
2432
+ group(docs.to),
2433
+ softline,
2434
+ docs.semicolon,
2435
+ ]),
2436
+ p.newLine(),
2437
+ ];
2438
+ };
2439
+ const printGroupedExpr = (path, options, print, node) => {
2440
+ const p = new Printer(path, options, print, node);
2441
+ p.setNotRoot("expr");
2442
+ const docs = {
2443
+ leading_comments: printLeadingComments(path, options, print, node),
2444
+ self: p.self(),
2445
+ trailing_comments: printTrailingComments(path, options, print, node),
2446
+ expr: p.child("expr"),
2447
+ rparen: p.child("rparen"),
2448
+ as: "",
2449
+ alias: printAlias(path, options, print, node),
2450
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
2451
+ unpivot: "",
2452
+ order: printOrder(path, options, print, node),
2453
+ null_order: "",
2454
+ comma: printComma(path, options, print, node),
2455
+ };
2456
+ return [
2457
+ docs.leading_comments,
2458
+ group([
2459
+ docs.self,
2460
+ docs.trailing_comments,
2461
+ indent([softline, docs.expr]),
2462
+ softline,
2463
+ docs.rparen,
2464
+ ]),
2465
+ docs.alias,
2466
+ docs.pivot,
2467
+ docs.order,
2468
+ docs.comma,
2469
+ ];
2470
+ };
2471
+ const printGroupedExprs = (path, options, print, node) => {
2472
+ const p = new Printer(path, options, print, node);
2473
+ p.setGroupRecommended("exprs");
2474
+ const docs = {
2475
+ leading_comments: printLeadingComments(path, options, print, node),
2476
+ self: p.self(),
2477
+ trailing_comments: printTrailingComments(path, options, print, node),
2478
+ exprs: p.child("exprs", undefined, "none", line),
2479
+ rparen: p.child("rparen"),
2480
+ as: p.has("as")
2481
+ ? p.child("as", undefined, "all")
2482
+ : options.printKeywordsInUpperCase
2483
+ ? "AS"
2484
+ : "as",
2485
+ row_value_alias: p.child("row_value_alias", undefined, "all"),
2486
+ comma: p.child("comma", undefined, "all"),
2487
+ };
2488
+ return [
2489
+ docs.leading_comments,
2490
+ group([
2491
+ docs.self,
2492
+ docs.trailing_comments,
2493
+ indent([softline, docs.exprs]),
2494
+ softline,
2495
+ docs.rparen,
2496
+ p.has("row_value_alias") ? [" ", docs.as] : "",
2497
+ p.has("row_value_alias") ? [" ", docs.row_value_alias] : "",
2498
+ ]),
2499
+ docs.comma,
2500
+ ];
2501
+ };
2502
+ const printGroupedIdentWithOptions = (path, options, print, node) => {
2503
+ const p = new Printer(path, options, print, node);
2504
+ const docs = {
2505
+ leading_comments: printLeadingComments(path, options, print, node),
2506
+ self: p.self(),
2507
+ trailing_comments: printTrailingComments(path, options, print, node),
2508
+ idents: p.child("idents", undefined, "none", line),
2509
+ rparen: p.child("rparen"),
2510
+ };
2511
+ return [
2512
+ docs.leading_comments,
2513
+ group([
2514
+ docs.self,
2515
+ docs.trailing_comments,
2516
+ indent([softline, docs.idents]),
2517
+ softline,
2518
+ docs.rparen,
2519
+ ]),
2520
+ ];
2521
+ };
2522
+ const printGroupedStatement = (path, options, print, node) => {
2523
+ const p = new Printer(path, options, print, node);
2524
+ p.setNotRoot("stmt");
2525
+ const docs = {
2526
+ with: p.child("with"),
2527
+ leading_comments: printLeadingComments(path, options, print, node),
2528
+ self: p.self(),
2529
+ trailing_comments: printTrailingComments(path, options, print, node),
2530
+ stmt: p.child("stmt"),
2531
+ rparen: p.child("rparen"),
2532
+ as: "",
2533
+ alias: printAlias(path, options, print, node),
2534
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
2535
+ unpivot: "",
2536
+ orderby: p.child("orderby"),
2537
+ limit: p.child("limit"),
2538
+ order: printOrder(path, options, print, node),
2539
+ null_order: "",
2540
+ comma: printComma(path, options, print, node),
2541
+ semicolon: p.child("semicolon", undefined, "all"),
2542
+ };
2543
+ return [
2544
+ group([
2545
+ docs.with,
2546
+ p.has("with")
2547
+ ? options.printBlankLineAfterCte
2548
+ ? [hardline, hardline]
2549
+ : hardline
2550
+ : "",
2551
+ ]),
2552
+ docs.leading_comments,
2553
+ group([
2554
+ p.has("with") ? breakParent : "",
2555
+ group([
2556
+ docs.self,
2557
+ docs.trailing_comments,
2558
+ indent([softline, group(docs.stmt)]),
2559
+ softline,
2560
+ docs.rparen,
2561
+ docs.pivot,
2562
+ ]),
2563
+ p.has("orderby") ? line : "",
2564
+ docs.orderby,
2565
+ p.has("limit") ? line : "",
2566
+ docs.limit,
2567
+ p.has("semicolon") ? softline : "",
2568
+ docs.semicolon,
2569
+ ]),
2570
+ docs.alias,
2571
+ docs.order,
2572
+ docs.comma,
2573
+ p.newLine(),
2574
+ ];
2575
+ };
2576
+ const printGroupedType = (path, options, print, node) => {
2577
+ const p = new Printer(path, options, print, node);
2578
+ const docs = {
2579
+ leading_comments: printLeadingComments(path, options, print, node),
2580
+ self: p.self(),
2581
+ trailing_comments: printTrailingComments(path, options, print, node),
2582
+ type: p.child("type"),
2583
+ rparen: p.child("rparen"),
2584
+ };
2585
+ return [
2586
+ docs.leading_comments,
2587
+ docs.self,
2588
+ docs.trailing_comments,
2589
+ indent([softline, docs.type]),
2590
+ softline,
2591
+ docs.rparen,
2592
+ ];
2593
+ };
2594
+ const printGroupedTypeDeclarations = (path, options, print, node) => {
2595
+ const p = new Printer(path, options, print, node);
2596
+ const docs = {
2597
+ leading_comments: printLeadingComments(path, options, print, node),
2598
+ self: p.self(),
2599
+ trailing_comments: printTrailingComments(path, options, print, node),
2600
+ declarations: p.child("declarations", (x) => group(x), "none", line),
2601
+ rparen: p.child("rparen"),
2602
+ };
2603
+ return [
2604
+ docs.leading_comments,
2605
+ docs.self,
2606
+ docs.trailing_comments,
2607
+ indent([p.has("declarations") ? softline : "", docs.declarations]),
2608
+ p.has("declarations") ? softline : "",
2609
+ docs.rparen,
2610
+ ];
2611
+ };
2612
+ const printIdentifier = (path, options, print, node) => {
2613
+ const p = new Printer(path, options, print, node);
2614
+ const docs = {
2615
+ leading_comments: printLeadingComments(path, options, print, node),
2616
+ self: node.isPreDefinedFunction || node.isDatePart ? p.self("upper") : p.self(),
2617
+ trailing_comments: printTrailingComments(path, options, print, node),
2618
+ as: "",
2619
+ alias: printAlias(path, options, print, node),
2620
+ for_system_time_as_of: p.child("for_system_time_as_of", undefined, "all"),
2621
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
2622
+ unpivot: "",
2623
+ tablesample: p.child("tablesample", undefined, "all"),
2624
+ order: printOrder(path, options, print, node),
2625
+ null_order: "",
2626
+ comma: printComma(path, options, print, node),
2627
+ };
2628
+ return [
2629
+ docs.leading_comments,
2630
+ docs.self,
2631
+ docs.trailing_comments,
2632
+ docs.alias,
2633
+ p.has("for_system_time_as_of") ? [" ", docs.for_system_time_as_of] : "",
2634
+ docs.pivot,
2635
+ p.has("tablesample") ? [" ", docs.tablesample] : "",
2636
+ docs.order,
2637
+ docs.comma,
2638
+ ];
2639
+ };
2640
+ const printIdentWithOptions = (path, options, print, node) => {
2641
+ const p = new Printer(path, options, print, node);
2642
+ const docs = {
2643
+ leading_comments: printLeadingComments(path, options, print, node),
2644
+ self: p.self(),
2645
+ trailing_comments: printTrailingComments(path, options, print, node),
2646
+ options: p.child("options", undefined, "all"),
2647
+ comma: printComma(path, options, print, node),
2648
+ };
2649
+ return [
2650
+ docs.leading_comments,
2651
+ docs.self,
2652
+ docs.trailing_comments,
2653
+ p.has("options") ? " " : "",
2654
+ docs.options,
2655
+ docs.comma,
2656
+ ];
2657
+ };
2658
+ const printIfStatement = (path, options, print, node) => {
2659
+ const p = new Printer(path, options, print, node);
2660
+ const docs = {
2661
+ leading_comments: printLeadingComments(path, options, print, node),
2662
+ self: p.self("upper"),
2663
+ trailing_comments: printTrailingComments(path, options, print, node),
2664
+ condition: p.child("condition", undefined, "all"),
2665
+ then: p.child("then", undefined, "all"),
2666
+ elseifs: p.child("elseifs", (x) => [hardline, x]),
2667
+ else: p.child("else"),
2668
+ end_if: group(p.child("end_if", undefined, "none", line)),
2669
+ semicolon: p.child("semicolon"),
2670
+ };
2671
+ return [
2672
+ docs.leading_comments,
2673
+ group([
2674
+ docs.self,
2675
+ docs.trailing_comments,
2676
+ " ",
2677
+ docs.condition,
2678
+ " ",
2679
+ docs.then,
2680
+ docs.elseifs,
2681
+ p.has("else") ? hardline : "",
2682
+ docs.else,
2683
+ line,
2684
+ docs.end_if,
2685
+ softline,
2686
+ docs.semicolon,
2687
+ ]),
2688
+ p.newLine(),
2689
+ ];
2690
+ };
2691
+ const printInOperator = (path, options, print, node) => {
2692
+ const p = new Printer(path, options, print, node);
2693
+ p.setNotRoot("right");
2694
+ const docs = {
2695
+ leading_comments: "",
2696
+ left: p.child("left"),
2697
+ not: p.child("not"),
2698
+ self: p.self("asItIs", true),
2699
+ trailing_comments: printTrailingComments(path, options, print, node),
2700
+ right: p.child("right", undefined, "all"),
2701
+ as: "",
2702
+ alias: printAlias(path, options, print, node),
2703
+ order: printOrder(path, options, print, node),
2704
+ null_order: "",
2705
+ comma: printComma(path, options, print, node),
2706
+ };
2707
+ return [
2708
+ docs.left,
2709
+ " ",
2710
+ p.has("not") ? [docs.not, " "] : "",
2711
+ docs.self,
2712
+ docs.trailing_comments,
2713
+ " ",
2714
+ docs.right,
2715
+ docs.alias,
2716
+ docs.order,
2717
+ docs.comma,
2718
+ ];
2719
+ };
2720
+ const printInsertStatement = (path, options, print, node) => {
2721
+ const p = new Printer(path, options, print, node);
2722
+ p.setNotRoot("input");
2723
+ const docs = {
2724
+ leading_comments: printLeadingComments(path, options, print, node),
2725
+ self: p.self("upper"),
2726
+ trailing_comments: printTrailingComments(path, options, print, node),
2727
+ into: p.consumeAllCommentsOfX("into"),
2728
+ target_name: p.child("target_name", undefined, "all"),
2729
+ columns: p.child("columns", undefined, "all"),
2730
+ input: p.child("input"),
2731
+ semicolon: p.child("semicolon"),
2732
+ };
2733
+ return [
2734
+ docs.leading_comments,
2735
+ group([
2736
+ docs.self,
2737
+ docs.trailing_comments,
2738
+ docs.into,
2739
+ p.has("target_name") ? " " : "",
2740
+ docs.target_name,
2741
+ p.has("columns") ? " " : "",
2742
+ docs.columns,
2743
+ line,
2744
+ docs.input,
2745
+ node.notRoot ? "" : softline,
2746
+ docs.semicolon,
2747
+ ]),
2748
+ p.newLine(),
2749
+ ];
2750
+ };
2751
+ const printIntervalLiteral = (path, options, print, node) => {
2752
+ const p = new Printer(path, options, print, node);
2753
+ const docs = {
2754
+ leading_comments: printLeadingComments(path, options, print, node),
2755
+ self: p.self("upper"),
2756
+ trailing_comments: printTrailingComments(path, options, print, node),
2757
+ expr: p.child("expr", undefined, "all"),
2758
+ date_part: p.child("date_part", undefined, "all"),
2759
+ to: p.child("to", undefined, "all"),
2760
+ to_date_part: p.child("to_date_part", undefined, "all"),
2761
+ as: "",
2762
+ alias: printAlias(path, options, print, node),
2763
+ comma: printComma(path, options, print, node),
2764
+ };
2765
+ return [
2766
+ docs.leading_comments,
2767
+ docs.self,
2768
+ docs.trailing_comments,
2769
+ " ",
2770
+ group(docs.expr),
2771
+ " ",
2772
+ docs.date_part,
2773
+ p.has("to") ? " " : "",
2774
+ docs.to,
2775
+ p.has("to_date_part") ? " " : "",
2776
+ docs.to_date_part,
2777
+ docs.alias,
2778
+ docs.comma,
2779
+ ];
2780
+ };
2781
+ const printIsDistinctFromOperator = (path, options, print, node) => {
2782
+ const p = new Printer(path, options, print, node);
2783
+ const leading_comments = p.consumeLeadingCommentsOfX("left", false);
2784
+ const docs = {
2785
+ leading_comments: leading_comments,
2786
+ left: p.child("left"),
2787
+ self: p.self("upper", true),
2788
+ trailing_comments: printTrailingComments(path, options, print, node),
2789
+ not: p.child("not", undefined, "all"),
2790
+ distinct: p.child("distinct", undefined, "all"),
2791
+ from: p.child("from", undefined, "all"),
2792
+ right: p.child("right", undefined, "all"),
2793
+ as: "",
2794
+ alias: printAlias(path, options, print, node),
2795
+ order: printOrder(path, options, print, node),
2796
+ null_order: "",
2797
+ comma: printComma(path, options, print, node),
2798
+ };
2799
+ return [
2800
+ docs.leading_comments,
2801
+ group([
2802
+ group(docs.left),
2803
+ line,
2804
+ group([
2805
+ docs.self,
2806
+ docs.trailing_comments,
2807
+ p.has("not") ? " " : "",
2808
+ docs.not,
2809
+ " ",
2810
+ docs.distinct,
2811
+ " ",
2812
+ docs.from,
2813
+ " ",
2814
+ group(docs.right),
2815
+ ]),
2816
+ ]),
2817
+ docs.alias,
2818
+ docs.order,
2819
+ docs.comma,
2820
+ ];
2821
+ };
2822
+ const printJoinOperator = (path, options, print, node) => {
2823
+ const p = new Printer(path, options, print, node);
2824
+ p.setNotRoot("left");
2825
+ p.setNotRoot("right");
2826
+ const docs = {
2827
+ leading_comments: "",
2828
+ left: p.child("left"),
2829
+ join_type: p.child("join_type"),
2830
+ outer: p.consumeAllCommentsOfX("outer"),
2831
+ self: p.self("upper", true),
2832
+ trailing_comments: printTrailingComments(path, options, print, node),
2833
+ right: p.child("right", undefined, "all"),
2834
+ on: p.child("on", undefined, "all"),
2835
+ using: p.child("using", undefined, "all"),
2836
+ as: "",
2837
+ alias: printAlias(path, options, print, node),
2838
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
2839
+ unpivot: "", // eslint-disable-line unicorn/no-unused-properties
2840
+ };
2841
+ return [
2842
+ docs.left,
2843
+ hardline,
2844
+ p.includedIn(["JOIN"])
2845
+ ? [
2846
+ docs.join_type ||
2847
+ (options.printKeywordsInUpperCase ? "INNER" : "inner"),
2848
+ " ",
2849
+ ]
2850
+ : "",
2851
+ docs.outer,
2852
+ docs.self,
2853
+ docs.trailing_comments,
2854
+ " ",
2855
+ docs.right,
2856
+ p.has("on") || p.has("using") ? " " : "",
2857
+ docs.on,
2858
+ docs.using,
2859
+ docs.alias,
2860
+ docs.pivot,
2861
+ ];
2862
+ };
2863
+ const printKeyword = (path, options, print, node) => {
2864
+ const p = new Printer(path, options, print, node);
2865
+ const docs = {
2866
+ leading_comments: printLeadingComments(path, options, print, node),
2867
+ self: p.self("upper"),
2868
+ trailing_comments: printTrailingComments(path, options, print, node),
2869
+ };
2870
+ return [docs.leading_comments, docs.self, docs.trailing_comments];
2871
+ };
2872
+ const printKeywordSequence = (path, options, print, node) => {
2873
+ const p = new Printer(path, options, print, node);
2874
+ const docs = {
2875
+ leading_comments: printLeadingComments(path, options, print, node),
2876
+ self: p.self("upper"),
2877
+ next_keyword: p.child("next_keyword", undefined, "all"),
2878
+ trailing_comments: printTrailingComments(path, options, print, node),
2879
+ };
2880
+ return [
2881
+ docs.leading_comments,
2882
+ docs.self,
2883
+ docs.trailing_comments,
2884
+ " ",
2885
+ docs.next_keyword,
2886
+ ];
2887
+ };
2888
+ const printKeywordWithExpr = (path, options, print, node) => {
2889
+ const p = new Printer(path, options, print, node);
2890
+ p.setNotRoot("expr");
2891
+ p.setBreakRecommended("expr"); // AND or OR
2892
+ p.setGroupRecommended("expr"); // other binary operator
2893
+ let indentExpr = true;
2894
+ if (!p.hasLeadingComments("expr")) {
2895
+ const token = node.children.expr.Node.token;
2896
+ if (!token)
2897
+ throw new Error("Something went wrong.");
2898
+ const node_type = node.children.expr.Node.node_type;
2899
+ if (node_type === "GroupedStatement") {
2900
+ // FROM (SELECT ...)
2901
+ indentExpr = false;
2902
+ }
2903
+ else if (node_type === "StringLiteral" &&
2904
+ token.literal.match(/^['"]{3}\n/)) {
2905
+ // AS '''const x = "aaa"; return x'''
2906
+ indentExpr = false;
2907
+ }
2908
+ else if (node_type === "UnaryOperator" &&
2909
+ token.literal.match(/^[brBR]{1,2}$/)) {
2910
+ // AS r'''const x = "aaa"; return x'''
2911
+ indentExpr = false;
2912
+ }
2913
+ }
2914
+ const docs = {
2915
+ leading_comments: printLeadingComments(path, options, print, node),
2916
+ self: p.self("upper"),
2917
+ trailing_comments: printTrailingComments(path, options, print, node),
2918
+ expr: indentExpr
2919
+ ? indent([line, p.child("expr")])
2920
+ : [" ", p.child("expr", undefined, "all")],
2921
+ };
2922
+ return [
2923
+ docs.leading_comments,
2924
+ group([docs.self, docs.trailing_comments, docs.expr]),
2925
+ ];
2926
+ };
2927
+ const printKeywordWithExprs = (path, options, print, node) => {
2928
+ const p = new Printer(path, options, print, node);
2929
+ p.setGroupRecommended("exprs");
2930
+ const docs = {
2931
+ leading_comments: printLeadingComments(path, options, print, node),
2932
+ self: p.self("upper"),
2933
+ trailing_comments: printTrailingComments(path, options, print, node),
2934
+ exprs: p.child("exprs", (x) => [line, x]),
2935
+ };
2936
+ let res = [docs.self, docs.trailing_comments, indent(docs.exprs)];
2937
+ if (p.len("exprs") === 1) {
2938
+ res = group(res);
2939
+ }
2940
+ return [docs.leading_comments, res];
2941
+ };
2942
+ const printKeywordWithGroupedXXX = (path, options, print, node) => {
2943
+ const p = new Printer(path, options, print, node);
2944
+ p.setNotRoot("group");
2945
+ const docs = {
2946
+ leading_comments: printLeadingComments(path, options, print, node),
2947
+ self: p.self("upper"),
2948
+ trailing_comments: printTrailingComments(path, options, print, node),
2949
+ group: p.child("group", undefined, "all"),
2950
+ };
2951
+ return [
2952
+ docs.leading_comments,
2953
+ group([docs.self, docs.trailing_comments, " ", docs.group]),
2954
+ ];
2955
+ };
2956
+ const printKeywordWithStatement = (path, options, print, node) => {
2957
+ const p = new Printer(path, options, print, node);
2958
+ p.setNotRoot("stmt");
2959
+ const docs = {
2960
+ leading_comments: printLeadingComments(path, options, print, node),
2961
+ self: p.self("upper"),
2962
+ trailing_comments: printTrailingComments(path, options, print, node),
2963
+ stmt: p.child("stmt"),
2964
+ };
2965
+ return [
2966
+ docs.leading_comments,
2967
+ group([docs.self, docs.trailing_comments, indent([line, docs.stmt])]),
2968
+ ];
2969
+ };
2970
+ const printKeywordWithStatements = (path, options, print, node) => {
2971
+ const p = new Printer(path, options, print, node);
2972
+ p.setNotRoot("stmts");
2973
+ const docs = {
2974
+ leading_comments: printLeadingComments(path, options, print, node),
2975
+ self: p.self("upper"),
2976
+ trailing_comments: printTrailingComments(path, options, print, node),
2977
+ stmts: p.len("stmts") <= 1
2978
+ ? p.child("stmts", (x) => [line, x])
2979
+ : p.child("stmts", (x) => [hardline, x]),
2980
+ };
2981
+ return [
2982
+ docs.leading_comments,
2983
+ docs.self,
2984
+ docs.trailing_comments,
2985
+ indent(docs.stmts),
2986
+ ];
2987
+ };
2988
+ const printKeywordWithType = (path, options, print, node) => {
2989
+ const p = new Printer(path, options, print, node);
2990
+ const docs = {
2991
+ leading_comments: printLeadingComments(path, options, print, node),
2992
+ self: p.self("upper"),
2993
+ trailing_comments: printTrailingComments(path, options, print, node),
2994
+ type: p.child("type"),
2995
+ };
2996
+ return [
2997
+ docs.leading_comments,
2998
+ group([docs.self, docs.trailing_comments, indent([line, docs.type])]),
2999
+ ];
3000
+ };
3001
+ const printLimitClause = (path, options, print, node) => {
3002
+ const p = new Printer(path, options, print, node);
3003
+ p.setNotRoot("expr");
3004
+ const docs = {
3005
+ leading_comments: printLeadingComments(path, options, print, node),
3006
+ self: p.self("upper"),
3007
+ trailing_comments: printTrailingComments(path, options, print, node),
3008
+ // NOTE expr is literal or parameter value
3009
+ expr: p.child("expr"),
3010
+ offset: p.child("offset", undefined, "all"),
3011
+ };
3012
+ return [
3013
+ docs.leading_comments,
3014
+ group([docs.self, docs.trailing_comments, " ", docs.expr]),
3015
+ p.has("offset") ? " " : "",
3016
+ docs.offset,
3017
+ ];
3018
+ };
3019
+ const printLoadStatement = (path, options, print, node) => {
3020
+ const p = new Printer(path, options, print, node);
3021
+ const docs = {
3022
+ leading_comments: printLeadingComments(path, options, print, node),
3023
+ self: p.self("upper"),
3024
+ trailing_comments: printTrailingComments(path, options, print, node),
3025
+ data: p.child("data", undefined, "all"),
3026
+ into: p.child("into", undefined, "all"),
3027
+ ident: p.child("ident", undefined, "all"),
3028
+ column_group: p.child("column_group", undefined, "all"),
3029
+ partitionby: p.child("partitionby"),
3030
+ clusterby: p.child("clusterby"),
3031
+ options: p.child("options"),
3032
+ from: p.child("from"),
3033
+ files: p.child("files", undefined, "all"),
3034
+ from_files: p.child("from_files", undefined, "all"),
3035
+ with_partition_columns: p.child("with_partition_columns"),
3036
+ with: p.child("with"),
3037
+ connection: p.child("connection", undefined, "all"),
3038
+ connection_name: p.child("connection_name", undefined, "all"),
3039
+ semicolon: p.child("semicolon"),
3040
+ };
3041
+ return [
3042
+ docs.leading_comments,
3043
+ group([
3044
+ docs.self,
3045
+ docs.trailing_comments,
3046
+ " ",
3047
+ docs.data,
3048
+ " ",
3049
+ docs.into,
3050
+ " ",
3051
+ docs.ident,
3052
+ p.has("column_group") ? " " : "",
3053
+ docs.column_group,
3054
+ p.has("partitionby") ? line : "",
3055
+ docs.partitionby,
3056
+ p.has("clusterby") ? line : "",
3057
+ docs.clusterby,
3058
+ p.has("options") ? line : "",
3059
+ docs.options,
3060
+ line,
3061
+ docs.from,
3062
+ " ",
3063
+ docs.files,
3064
+ " ",
3065
+ docs.from_files,
3066
+ p.has("with_partition_columns") ? line : "",
3067
+ docs.with_partition_columns,
3068
+ p.has("with") ? line : "",
3069
+ docs.with,
3070
+ p.has("with") ? " " : "",
3071
+ docs.connection,
3072
+ p.has("with") ? " " : "",
3073
+ docs.connection_name,
3074
+ softline,
3075
+ docs.semicolon,
3076
+ ]),
3077
+ p.newLine(),
3078
+ ];
3079
+ };
3080
+ const printLoopStatement = (path, options, print, node) => {
3081
+ const p = new Printer(path, options, print, node);
3082
+ p.setNotRoot("stmts");
3083
+ let leading_label_comments = "";
3084
+ if (node.children.leading_label &&
3085
+ node.children.leading_label.Node.children.leading_comments) {
3086
+ leading_label_comments =
3087
+ node.children.leading_label.Node.children.leading_comments.NodeVec.map((n) => [n.token.literal, hardline]);
3088
+ p.consumeLeadingCommentsOfX("leading_label");
3089
+ }
3090
+ const docs = {
3091
+ leading_label: p.child("leading_label"),
3092
+ colon: p.child("colon", undefined, "all"),
3093
+ leading_comments: printLeadingComments(path, options, print, node),
3094
+ self: p.self("upper"),
3095
+ trailing_comments: printTrailingComments(path, options, print, node),
3096
+ stmts: p.len("stmts") <= 1
3097
+ ? p.child("stmts", (x) => [line, x])
3098
+ : p.child("stmts", (x) => [hardline, x]),
3099
+ end_loop: group(p.child("end_loop", undefined, "none", line)),
3100
+ trailing_label: p.child("trailing_label", undefined, "all"),
3101
+ semicolon: p.child("semicolon"),
3102
+ };
3103
+ return [
3104
+ leading_label_comments,
3105
+ docs.leading_comments,
3106
+ group([
3107
+ docs.leading_label,
3108
+ docs.colon,
3109
+ p.has("leading_label") ? " " : "",
3110
+ docs.self,
3111
+ docs.trailing_comments,
3112
+ indent(docs.stmts),
3113
+ line,
3114
+ docs.end_loop,
3115
+ p.has("trailing_label") ? " " : "",
3116
+ docs.trailing_label,
3117
+ softline,
3118
+ docs.semicolon,
3119
+ ]),
3120
+ p.newLine(),
3121
+ ];
3122
+ };
3123
+ const printMergeStatement = (path, options, print, node) => {
3124
+ const p = new Printer(path, options, print, node);
3125
+ const docs = {
3126
+ leading_comments: printLeadingComments(path, options, print, node),
3127
+ self: p.self("upper"),
3128
+ trailing_comments: printTrailingComments(path, options, print, node),
3129
+ into: p.consumeAllCommentsOfX("into"),
3130
+ table_name: p.child("table_name", undefined, "all"),
3131
+ using: p.child("using"),
3132
+ on: p.child("on"),
3133
+ whens: p.child("whens", (x) => [line, x]),
3134
+ semicolon: p.child("semicolon"),
3135
+ };
3136
+ return [
3137
+ docs.leading_comments,
3138
+ group([
3139
+ docs.self,
3140
+ docs.trailing_comments,
3141
+ docs.into,
3142
+ " ",
3143
+ docs.table_name,
3144
+ line,
3145
+ docs.using,
3146
+ line,
3147
+ docs.on,
3148
+ docs.whens,
3149
+ softline,
3150
+ docs.semicolon,
3151
+ ]),
3152
+ p.newLine(),
3153
+ ];
3154
+ };
3155
+ const printMultiTokenIdentifier = (path, options, print, node) => {
3156
+ const p = new Printer(path, options, print, node);
3157
+ const docs = {
3158
+ leading_comments: printLeadingComments(path, options, print, node),
3159
+ self: p.self(),
3160
+ trailing_comments: printTrailingComments(path, options, print, node),
3161
+ trailing_idents: p.child("trailing_idents", undefined, "all"),
3162
+ as: "",
3163
+ alias: printAlias(path, options, print, node),
3164
+ for_system_time_as_of: p.child("for_system_time_as_of", undefined, "all"),
3165
+ pivot: printPivotOrUnpivotOperator(path, options, print, node),
3166
+ unpivot: "",
3167
+ tablesample: p.child("tablesample", undefined, "all"),
3168
+ // NOTE order, null_order, comma may be unnecessary for the time being.
3169
+ order: printOrder(path, options, print, node),
3170
+ null_order: "",
3171
+ comma: printComma(path, options, print, node),
3172
+ };
3173
+ return [
3174
+ docs.leading_comments,
3175
+ docs.self,
3176
+ docs.trailing_comments,
3177
+ docs.trailing_idents,
3178
+ docs.alias,
3179
+ p.has("for_system_time_as_of") ? [" ", docs.for_system_time_as_of] : "",
3180
+ docs.pivot,
3181
+ p.has("tablesample") ? [" ", docs.tablesample] : "",
3182
+ docs.order,
3183
+ docs.comma,
3184
+ ];
3185
+ };
3186
+ const printNullLiteral = (path, options, print, node) => {
3187
+ const p = new Printer(path, options, print, node);
3188
+ const docs = {
3189
+ leading_comments: printLeadingComments(path, options, print, node),
3190
+ self: p.self("upper"),
3191
+ trailing_comments: printTrailingComments(path, options, print, node),
3192
+ as: "",
3193
+ alias: printAlias(path, options, print, node),
3194
+ order: printOrder(path, options, print, node),
3195
+ null_order: "",
3196
+ comma: printComma(path, options, print, node),
3197
+ };
3198
+ return [
3199
+ docs.leading_comments,
3200
+ docs.self,
3201
+ docs.trailing_comments,
3202
+ docs.alias,
3203
+ docs.order,
3204
+ docs.comma,
3205
+ ];
3206
+ };
3207
+ const printNumericLiteral = (path, options, print, node) => {
3208
+ const p = new Printer(path, options, print, node);
3209
+ const docs = {
3210
+ leading_comments: printLeadingComments(path, options, print, node),
3211
+ self: p.self("lower"),
3212
+ trailing_comments: printTrailingComments(path, options, print, node),
3213
+ as: "",
3214
+ alias: printAlias(path, options, print, node),
3215
+ order: printOrder(path, options, print, node),
3216
+ null_order: "",
3217
+ comma: printComma(path, options, print, node),
3218
+ };
3219
+ return [
3220
+ docs.leading_comments,
3221
+ docs.self,
3222
+ docs.trailing_comments,
3223
+ docs.alias,
3224
+ docs.order,
3225
+ docs.comma,
3226
+ ];
3227
+ };
3228
+ const printOverClause = (path, options, print, node) => {
3229
+ const p = new Printer(path, options, print, node);
3230
+ const docs = {
3231
+ leading_comments: "",
3232
+ self: p.self("upper", true),
3233
+ trailing_comments: printTrailingComments(path, options, print, node),
3234
+ window: p.child("window", (x) => [" ", x], "all"),
3235
+ };
3236
+ return group([docs.self, docs.trailing_comments, docs.window]);
3237
+ };
3238
+ const printPivotConfig = (path, options, print, node) => {
3239
+ const p = new Printer(path, options, print, node);
3240
+ const docs = {
3241
+ leading_comments: printLeadingComments(path, options, print, node),
3242
+ self: p.self("upper"),
3243
+ trailing_comments: printTrailingComments(path, options, print, node),
3244
+ exprs: p.child("exprs", (x) => [x, line]),
3245
+ for: p.child("for"),
3246
+ in: p.child("in", undefined, "all"),
3247
+ rparen: p.child("rparen"),
3248
+ };
3249
+ return [
3250
+ docs.leading_comments,
3251
+ docs.self,
3252
+ docs.trailing_comments,
3253
+ indent([softline, docs.exprs, docs.for, " ", docs.in]),
3254
+ softline,
3255
+ docs.rparen,
3256
+ ];
3257
+ };
3258
+ const printPivotOperator = (path, options, print, node) => {
3259
+ const p = new Printer(path, options, print, node);
3260
+ const docs = {
3261
+ leading_comments: printLeadingComments(path, options, print, node),
3262
+ self: p.self("upper"),
3263
+ trailing_comments: printTrailingComments(path, options, print, node),
3264
+ config: p.child("config", undefined, "all"),
3265
+ as: p.child("as", undefined, "all"),
3266
+ alias: p.child("alias", undefined, "all"),
3267
+ };
3268
+ return [
3269
+ docs.leading_comments,
3270
+ docs.self,
3271
+ docs.trailing_comments,
3272
+ " ",
3273
+ docs.config,
3274
+ p.has("alias")
3275
+ ? [" ", docs.as || (options.printKeywordsInUpperCase ? "AS" : "as")]
3276
+ : "",
3277
+ p.has("alias") ? [" ", docs.alias] : "",
3278
+ ];
3279
+ };
3280
+ const printRevokeStatement = (path, options, print, node) => {
3281
+ const p = new Printer(path, options, print, node);
3282
+ const docs = {
3283
+ leading_comments: printLeadingComments(path, options, print, node),
3284
+ self: p.self("upper"),
3285
+ trailing_comments: printTrailingComments(path, options, print, node),
3286
+ roles: p.child("roles", (x) => [line, x]),
3287
+ on: p.child("on"),
3288
+ resource_type: p.child("resource_type", undefined, "all"),
3289
+ ident: p.child("ident", undefined, "all"),
3290
+ from: p.child("from"),
3291
+ semicolon: p.child("semicolon"),
3292
+ };
3293
+ return [
3294
+ docs.leading_comments,
3295
+ group([
3296
+ group([docs.self, docs.trailing_comments, docs.roles]),
3297
+ line,
3298
+ docs.on,
3299
+ " ",
3300
+ docs.resource_type,
3301
+ " ",
3302
+ docs.ident,
3303
+ line,
3304
+ group(docs.from),
3305
+ softline,
3306
+ docs.semicolon,
3307
+ ]),
3308
+ p.newLine(),
3309
+ ];
3310
+ };
3311
+ const printRaiseStatement = (path, options, print, node) => {
3312
+ const p = new Printer(path, options, print, node);
3313
+ const docs = {
3314
+ leading_comments: printLeadingComments(path, options, print, node),
3315
+ self: p.self("upper"),
3316
+ trailing_comments: printTrailingComments(path, options, print, node),
3317
+ using: p.child("using", undefined, "all"),
3318
+ semicolon: p.child("semicolon"),
3319
+ };
3320
+ return [
3321
+ docs.leading_comments,
3322
+ group([
3323
+ docs.self,
3324
+ docs.trailing_comments,
3325
+ p.has("using") ? " " : "",
3326
+ docs.using,
3327
+ softline,
3328
+ docs.semicolon,
3329
+ ]),
3330
+ p.newLine(),
3331
+ ];
3332
+ };
3333
+ const printRenameColumnClause = (path, options, print, node) => {
3334
+ const p = new Printer(path, options, print, node);
3335
+ const docs = {
3336
+ leading_comments: printLeadingComments(path, options, print, node),
3337
+ self: p.self("upper"),
3338
+ column: p.child("column", undefined, "all"),
3339
+ if_exists: p.child("if_exists", undefined, "all"),
3340
+ ident: p.child("ident", undefined, "all"),
3341
+ to: p.child("to", undefined, "all"),
3342
+ trailing_comments: printTrailingComments(path, options, print, node),
3343
+ comma: p.child("comma", undefined, "all"),
3344
+ };
3345
+ return [
3346
+ docs.leading_comments,
3347
+ group([
3348
+ docs.self,
3349
+ docs.trailing_comments,
3350
+ " ",
3351
+ docs.column,
3352
+ p.has("if_exists") ? " " : "",
3353
+ docs.if_exists,
3354
+ " ",
3355
+ docs.ident,
3356
+ " ",
3357
+ docs.to,
3358
+ docs.comma,
3359
+ ]),
3360
+ ];
3361
+ };
3362
+ const printRepeatStatement = (path, options, print, node) => {
3363
+ const p = new Printer(path, options, print, node);
3364
+ p.setNotRoot("stmts");
3365
+ let leading_label_comments = "";
3366
+ if (node.children.leading_label &&
3367
+ node.children.leading_label.Node.children.leading_comments) {
3368
+ leading_label_comments =
3369
+ node.children.leading_label.Node.children.leading_comments.NodeVec.map((n) => [n.token.literal, hardline]);
3370
+ p.consumeLeadingCommentsOfX("leading_label");
3371
+ }
3372
+ const docs = {
3373
+ leading_label: p.child("leading_label"),
3374
+ colon: p.child("colon", undefined, "all"),
3375
+ leading_comments: printLeadingComments(path, options, print, node),
3376
+ self: p.self("upper"),
3377
+ trailing_comments: printTrailingComments(path, options, print, node),
3378
+ stmts: p.len("stmts") <= 1
3379
+ ? p.child("stmts", (x) => [line, x])
3380
+ : p.child("stmts", (x) => [hardline, x]),
3381
+ until: p.child("until"),
3382
+ end_repeat: group(p.child("end_repeat", undefined, "none", line)),
3383
+ trailing_label: p.child("trailing_label", undefined, "all"),
3384
+ semicolon: p.child("semicolon"),
3385
+ };
3386
+ return [
3387
+ leading_label_comments,
3388
+ docs.leading_comments,
3389
+ group([
3390
+ docs.leading_label,
3391
+ docs.colon,
3392
+ p.has("leading_label") ? " " : "",
3393
+ docs.self,
3394
+ docs.trailing_comments,
3395
+ indent(docs.stmts),
3396
+ line,
3397
+ docs.until,
3398
+ line,
3399
+ docs.end_repeat,
3400
+ p.has("trailing_label") ? " " : "",
3401
+ docs.trailing_label,
3402
+ softline,
3403
+ docs.semicolon,
3404
+ ]),
3405
+ p.newLine(),
3406
+ ];
3407
+ };
3408
+ const printSelectStatement = (path, options, print, node) => {
3409
+ const p = new Printer(path, options, print, node);
3410
+ p.setNotRoot("exprs");
3411
+ p.setGroupRecommended("exprs");
3412
+ node.children.exprs.NodeVec[p.len("exprs") - 1].isFinalColumn = true;
3413
+ const docs = {
3414
+ with: p.child("with"),
3415
+ leading_comments: printLeadingComments(path, options, print, node),
3416
+ // SELECT clause
3417
+ self: p.self("upper"),
3418
+ differential_privacy: p.child("differential_privacy", undefined, "first"),
3419
+ as_struct_or_value: p.child("as_struct_or_value", undefined, "all", " "),
3420
+ distinct_or_all: p.child("distinct_or_all"),
3421
+ trailing_comments: printTrailingComments(path, options, print, node),
3422
+ exprs: p.child("exprs", (x) => [line, x]),
3423
+ // FROM clause
3424
+ from: p.child("from"),
3425
+ // WHERE clause
3426
+ where: p.child("where"),
3427
+ // GROUP BY clause
3428
+ groupby: p.child("groupby"),
3429
+ // HAVING clause
3430
+ having: p.child("having"),
3431
+ // QUALIFY clause
3432
+ qualify: p.child("qualify"),
3433
+ // WINDOW clause
3434
+ window: p.child("window"),
3435
+ // ORDER BY clause
3436
+ orderby: p.child("orderby"),
3437
+ // LIMIT clause
3438
+ limit: p.child("limit"),
3439
+ semicolon: p.child("semicolon", undefined, "all"),
3440
+ };
3441
+ const select = [
3442
+ docs.self,
3443
+ p.has("differential_privacy") ? " " : "",
3444
+ docs.differential_privacy,
3445
+ p.has("as_struct_or_value") ? " " : "",
3446
+ docs.as_struct_or_value,
3447
+ p.has("distinct_or_all") ? " " : "",
3448
+ docs.distinct_or_all,
3449
+ indent(docs.exprs),
3450
+ ];
3451
+ return [
3452
+ group([
3453
+ // WITH clause
3454
+ docs.with,
3455
+ p.has("with")
3456
+ ? options.printBlankLineAfterCte
3457
+ ? [hardline, hardline]
3458
+ : hardline
3459
+ : "",
3460
+ ]),
3461
+ docs.leading_comments,
3462
+ group([
3463
+ p.has("with") ? breakParent : "",
3464
+ // SELECT clause
3465
+ docs.trailing_comments,
3466
+ p.len("exprs") === 1 ? group(select) : select,
3467
+ // FROM clause
3468
+ p.has("from") ? line : "",
3469
+ docs.from,
3470
+ // WHERE clause
3471
+ p.has("where") ? line : "",
3472
+ docs.where,
3473
+ // GROUP BY clause
3474
+ p.has("groupby") ? line : "",
3475
+ docs.groupby,
3476
+ // HAVING clause
3477
+ p.has("having") ? line : "",
3478
+ docs.having,
3479
+ // QUALIFY clause
3480
+ p.has("qualify") ? line : "",
3481
+ docs.qualify,
3482
+ // WINDOW clause
3483
+ p.has("window") ? line : "",
3484
+ docs.window,
3485
+ // ORDER BY clause
3486
+ p.has("orderby") ? line : "",
3487
+ docs.orderby,
3488
+ // LIMIT clause
3489
+ p.has("limit") ? line : "",
3490
+ docs.limit,
3491
+ p.has("semicolon") ? [softline, docs.semicolon] : "",
3492
+ ]),
3493
+ p.newLine(),
3494
+ ];
3495
+ };
3496
+ const printSetOperator = (path, options, print, node) => {
3497
+ const p = new Printer(path, options, print, node);
3498
+ p.setNotRoot("left");
3499
+ p.setNotRoot("right");
3500
+ const docs = {
3501
+ with: p.child("with"),
3502
+ left: p.child("left"),
3503
+ leading_comments: printLeadingComments(path, options, print, node),
3504
+ self: p.self("upper"),
3505
+ trailing_comments: printTrailingComments(path, options, print, node),
3506
+ distinct_or_all: p.child("distinct_or_all", undefined, "all"),
3507
+ right: p.child("right"),
3508
+ semicolon: p.child("semicolon", undefined, "all"),
3509
+ };
3510
+ const res = [
3511
+ docs.with,
3512
+ p.has("with") ? line : "",
3513
+ docs.left,
3514
+ line,
3515
+ docs.leading_comments,
3516
+ docs.self,
3517
+ docs.trailing_comments,
3518
+ " ",
3519
+ docs.distinct_or_all,
3520
+ line,
3521
+ docs.right,
3522
+ p.has("semicolon") ? softline : "",
3523
+ docs.semicolon,
3524
+ p.newLine(),
3525
+ ];
3526
+ if (node.notRoot) {
3527
+ return res;
3528
+ }
3529
+ else {
3530
+ return group(res);
3531
+ }
3532
+ };
3533
+ const printSetStatement = (path, options, print, node) => {
3534
+ const p = new Printer(path, options, print, node);
3535
+ p.setGroupRecommended("expr");
3536
+ const docs = {
3537
+ leading_comments: printLeadingComments(path, options, print, node),
3538
+ self: p.self("upper"),
3539
+ trailing_comments: printTrailingComments(path, options, print, node),
3540
+ expr: p.child("expr"),
3541
+ semicolon: p.child("semicolon"),
3542
+ };
3543
+ return [
3544
+ docs.leading_comments,
3545
+ group([
3546
+ docs.self,
3547
+ docs.trailing_comments,
3548
+ indent([line, docs.expr]),
3549
+ softline,
3550
+ docs.semicolon,
3551
+ ]),
3552
+ p.newLine(),
3553
+ ];
3554
+ };
3555
+ const printSingleTokenStatement = (path, options, print, node) => {
3556
+ const p = new Printer(path, options, print, node);
3557
+ const docs = {
3558
+ leading_comments: printLeadingComments(path, options, print, node),
3559
+ self: p.self("upper"),
3560
+ trailing_comments: printTrailingComments(path, options, print, node),
3561
+ semicolon: p.child("semicolon"),
3562
+ };
3563
+ return [
3564
+ docs.leading_comments,
3565
+ docs.self,
3566
+ docs.trailing_comments,
3567
+ docs.semicolon,
3568
+ p.newLine(),
3569
+ ];
3570
+ };
3571
+ const printStringLiteral = (path, options, print, node) => {
3572
+ const p = new Printer(path, options, print, node);
3573
+ const docs = {
3574
+ leading_comments: printLeadingComments(path, options, print, node),
3575
+ self: p.self(),
3576
+ trailing_comments: printTrailingComments(path, options, print, node),
3577
+ as: "",
3578
+ alias: printAlias(path, options, print, node),
3579
+ order: printOrder(path, options, print, node),
3580
+ null_order: "",
3581
+ comma: printComma(path, options, print, node),
3582
+ };
3583
+ return [
3584
+ p.node.token.literal.includes("\n") ? breakParent : "",
3585
+ docs.leading_comments,
3586
+ docs.self,
3587
+ docs.trailing_comments,
3588
+ docs.alias,
3589
+ docs.order,
3590
+ docs.comma,
3591
+ ];
3592
+ };
3593
+ const printStructLiteral = (path, options, print, node) => {
3594
+ const p = new Printer(path, options, print, node);
3595
+ const docs = {
3596
+ type: p.child("type"),
3597
+ leading_comments: p.has("type")
3598
+ ? ""
3599
+ : printLeadingComments(path, options, print, node),
3600
+ self: p.has("type") ? p.self("asItIs", true) : p.self(),
3601
+ trailing_comments: printTrailingComments(path, options, print, node),
3602
+ exprs: p.child("exprs", (x) => group(x), "none", line),
3603
+ rparen: p.child("rparen"),
3604
+ as: "",
3605
+ alias: printAlias(path, options, print, node),
3606
+ order: printOrder(path, options, print, node),
3607
+ null_order: "",
3608
+ comma: printComma(path, options, print, node),
3609
+ };
3610
+ return [
3611
+ group([
3612
+ docs.type,
3613
+ docs.leading_comments,
3614
+ group([
3615
+ docs.self,
3616
+ docs.trailing_comments,
3617
+ indent([softline, docs.exprs]),
3618
+ softline,
3619
+ docs.rparen,
3620
+ ]),
3621
+ ]),
3622
+ docs.alias,
3623
+ docs.order,
3624
+ docs.comma,
3625
+ ];
3626
+ };
3627
+ const printSymbol = (path, options, print, node) => {
3628
+ const p = new Printer(path, options, print, node);
3629
+ const docs = {
3630
+ leading_comments: printLeadingComments(path, options, print, node),
3631
+ self: p.self("upper"),
3632
+ trailing_comments: printTrailingComments(path, options, print, node),
3633
+ };
3634
+ return [docs.leading_comments, docs.self, docs.trailing_comments];
3635
+ };
3636
+ const printTableSampleClause = (path, options, print, node) => {
3637
+ const p = new Printer(path, options, print, node);
3638
+ const docs = {
3639
+ leading_comments: printLeadingComments(path, options, print, node),
3640
+ self: p.self("upper"),
3641
+ system: p.child("system", undefined, "all"),
3642
+ trailing_comments: printTrailingComments(path, options, print, node),
3643
+ group: p.child("group", undefined, "all"),
3644
+ };
3645
+ return [
3646
+ docs.leading_comments,
3647
+ docs.self,
3648
+ docs.trailing_comments,
3649
+ " ",
3650
+ docs.system,
3651
+ " ",
3652
+ docs.group,
3653
+ ];
3654
+ };
3655
+ const printTableSampleRatio = (path, options, print, node) => {
3656
+ const p = new Printer(path, options, print, node);
3657
+ const docs = {
3658
+ leading_comments: printLeadingComments(path, options, print, node),
3659
+ self: p.self("upper"),
3660
+ expr: p.child("expr", undefined, "all"),
3661
+ trailing_comments: printTrailingComments(path, options, print, node),
3662
+ percent: p.child("percent", undefined, "all"),
3663
+ rparen: p.child("rparen", undefined, "all"),
3664
+ };
3665
+ return [
3666
+ docs.leading_comments,
3667
+ docs.self,
3668
+ docs.trailing_comments,
3669
+ docs.expr,
3670
+ " ",
3671
+ docs.percent,
3672
+ docs.rparen,
3673
+ ];
3674
+ };
3675
+ const printTransactionStatement = (path, options, print, node) => {
3676
+ const p = new Printer(path, options, print, node);
3677
+ const docs = {
3678
+ leading_comments: printLeadingComments(path, options, print, node),
3679
+ self: p.self("upper"),
3680
+ trailing_comments: printTrailingComments(path, options, print, node),
3681
+ transaction: p.child("transaction", undefined, "all"),
3682
+ semicolon: p.child("semicolon", undefined, "all"),
3683
+ };
3684
+ return [
3685
+ docs.leading_comments,
3686
+ docs.self,
3687
+ docs.trailing_comments,
3688
+ p.has("transaction") ? " " : "",
3689
+ docs.transaction,
3690
+ docs.semicolon,
3691
+ p.newLine(),
3692
+ ];
3693
+ };
3694
+ const printTruncateStatement = (path, options, print, node) => {
3695
+ const p = new Printer(path, options, print, node);
3696
+ const docs = {
3697
+ leading_comments: printLeadingComments(path, options, print, node),
3698
+ self: p.self("upper"),
3699
+ table: p.child("table", undefined, "all"),
3700
+ trailing_comments: printTrailingComments(path, options, print, node),
3701
+ table_name: p.child("table_name", undefined, "all"),
3702
+ semicolon: p.child("semicolon", undefined, "all"),
3703
+ };
3704
+ return [
3705
+ docs.leading_comments,
3706
+ docs.self,
3707
+ docs.trailing_comments,
3708
+ " ",
3709
+ docs.table,
3710
+ " ",
3711
+ docs.table_name,
3712
+ docs.semicolon,
3713
+ p.newLine(),
3714
+ ];
3715
+ };
3716
+ const printType = (path, options, print, node) => {
3717
+ const p = new Printer(path, options, print, node);
3718
+ const docs = {
3719
+ leading_comments: printLeadingComments(path, options, print, node),
3720
+ self: p.self("upper"),
3721
+ trailing_comments: printTrailingComments(path, options, print, node),
3722
+ type: p.child("type", undefined, "all"),
3723
+ type_declaration: p.child("type_declaration", undefined, "all"),
3724
+ parameter: p.child("parameter", undefined, "all"),
3725
+ collate: p.child("collate", undefined, "all"),
3726
+ constraint: p.child("constraint", undefined, "all"),
3727
+ primarykey: p.child("primarykey", undefined, "all"),
3728
+ references: p.child("references", undefined, "all"),
3729
+ enforced: p.child("enforced", undefined, "all"),
3730
+ not_null: p.child("not_null", (x) => group([line, x])),
3731
+ default: p.child("default", undefined, "all"),
3732
+ options: p.child("options", undefined, "all"), // OPTIONS()
3733
+ };
3734
+ return [
3735
+ docs.leading_comments,
3736
+ docs.self,
3737
+ docs.trailing_comments,
3738
+ p.has("type") ? " " : "",
3739
+ docs.type,
3740
+ group(docs.type_declaration),
3741
+ docs.parameter,
3742
+ p.has("collate") ? line : "",
3743
+ docs.collate,
3744
+ p.has("constraint") ? line : "",
3745
+ docs.constraint,
3746
+ p.has("primarykey") ? line : "",
3747
+ docs.primarykey,
3748
+ p.has("references") ? " " : "",
3749
+ docs.references,
3750
+ p.has("enforced") ? " " : "",
3751
+ docs.enforced,
3752
+ docs.not_null,
3753
+ p.has("default") ? line : "",
3754
+ docs.default,
3755
+ p.has("options") ? line : "",
3756
+ docs.options,
3757
+ ];
3758
+ };
3759
+ const printTypeDeclaration = (path, options, print, node) => {
3760
+ const p = new Printer(path, options, print, node);
3761
+ const docs = {
3762
+ leading_comments: "",
3763
+ in_out: p.child("in_out"),
3764
+ self: p.self("asItIs", true),
3765
+ trailing_comments: printTrailingComments(path, options, print, node),
3766
+ type: p.child("type", undefined, "all"),
3767
+ comma: p.child("comma", undefined, "all"),
3768
+ };
3769
+ return [
3770
+ docs.in_out,
3771
+ p.has("in_out") ? " " : "",
3772
+ docs.self,
3773
+ node.token ? " " : "",
3774
+ docs.trailing_comments,
3775
+ docs.type,
3776
+ docs.comma,
3777
+ ];
3778
+ };
3779
+ const printUnaryOperator = (path, options, print, node) => {
3780
+ const p = new Printer(path, options, print, node);
3781
+ const lowerCaseOperators = ["b", "br", "r", "rb"];
3782
+ const noSpaceOperators = [
3783
+ "+",
3784
+ "-",
3785
+ "~",
3786
+ "br",
3787
+ "r",
3788
+ "rb",
3789
+ "b",
3790
+ "ARRAY",
3791
+ "STRUCT",
3792
+ ];
3793
+ const docs = {
3794
+ leading_comments: printLeadingComments(path, options, print, node),
3795
+ self: p.includedIn(lowerCaseOperators) ? p.self("lower") : p.self("upper"),
3796
+ trailing_comments: printTrailingComments(path, options, print, node),
3797
+ right: p.child("right", undefined, "all"),
3798
+ as: "",
3799
+ alias: printAlias(path, options, print, node),
3800
+ order: printOrder(path, options, print, node),
3801
+ null_order: "",
3802
+ comma: printComma(path, options, print, node),
3803
+ };
3804
+ return [
3805
+ docs.leading_comments,
3806
+ docs.self,
3807
+ docs.trailing_comments,
3808
+ p.includedIn(noSpaceOperators) ? "" : " ",
3809
+ docs.right,
3810
+ docs.alias,
3811
+ docs.order,
3812
+ docs.comma,
3813
+ ];
3814
+ };
3815
+ const printUnpivotConfig = (path, options, print, node) => {
3816
+ const p = new Printer(path, options, print, node);
3817
+ const docs = {
3818
+ leading_comments: printLeadingComments(path, options, print, node),
3819
+ self: p.self("upper"),
3820
+ trailing_comments: printTrailingComments(path, options, print, node),
3821
+ expr: p.child("expr"),
3822
+ for: p.child("for"),
3823
+ in: p.child("in", undefined, "all"),
3824
+ rparen: p.child("rparen"),
3825
+ };
3826
+ return [
3827
+ docs.leading_comments,
3828
+ docs.self,
3829
+ docs.trailing_comments,
3830
+ indent([softline, docs.expr, line, docs.for, " ", docs.in]),
3831
+ softline,
3832
+ docs.rparen,
3833
+ ];
3834
+ };
3835
+ const printUnpivotOperator = (path, options, print, node) => {
3836
+ const p = new Printer(path, options, print, node);
3837
+ const docs = {
3838
+ leading_comments: printLeadingComments(path, options, print, node),
3839
+ self: p.self("upper"),
3840
+ include_or_exclude_nulls: p.child("include_or_exclude_nulls", (x) => group([line, x])),
3841
+ trailing_comments: printTrailingComments(path, options, print, node),
3842
+ config: p.child("config", undefined, "all"),
3843
+ as: p.child("as", undefined, "all"),
3844
+ alias: p.child("alias", undefined, "all"),
3845
+ };
3846
+ return [
3847
+ docs.leading_comments,
3848
+ docs.self,
3849
+ docs.include_or_exclude_nulls,
3850
+ docs.trailing_comments,
3851
+ " ",
3852
+ docs.config,
3853
+ p.has("alias")
3854
+ ? [" ", docs.as || (options.printKeywordsInUpperCase ? "AS" : "as")]
3855
+ : "",
3856
+ p.has("alias") ? [" ", docs.alias] : "",
3857
+ ];
3858
+ };
3859
+ const printUpdateStatement = (path, options, print, node) => {
3860
+ const p = new Printer(path, options, print, node);
3861
+ const docs = {
3862
+ leading_comments: printLeadingComments(path, options, print, node),
3863
+ self: p.self("upper"),
3864
+ trailing_comments: printTrailingComments(path, options, print, node),
3865
+ table_name: p.child("table_name", undefined, "all"),
3866
+ set: p.child("set"),
3867
+ from: p.child("from"),
3868
+ where: p.child("where"),
3869
+ semicolon: p.child("semicolon"),
3870
+ };
3871
+ return [
3872
+ docs.leading_comments,
3873
+ group([
3874
+ docs.self,
3875
+ docs.trailing_comments,
3876
+ p.has("table_name") ? " " : "",
3877
+ docs.table_name,
3878
+ line,
3879
+ docs.set,
3880
+ p.has("from") ? line : "",
3881
+ docs.from,
3882
+ line,
3883
+ docs.where,
3884
+ node.notRoot ? "" : softline,
3885
+ docs.semicolon,
3886
+ ]),
3887
+ p.newLine(),
3888
+ ];
3889
+ };
3890
+ const printWhenClause = (path, options, print, node) => {
3891
+ const p = new Printer(path, options, print, node);
3892
+ const docs = {
3893
+ leading_comments: printLeadingComments(path, options, print, node),
3894
+ self: p.self("upper"),
3895
+ not: p.child("not", undefined, "all"),
3896
+ trailing_comments: printTrailingComments(path, options, print, node),
3897
+ matched: p.child("matched", undefined, "all"),
3898
+ by_target_or_source: p.child("by_target_or_source", (x) => group([line, x])),
3899
+ and: p.child("and", undefined, "all"),
3900
+ then: p.child("then", undefined, "all"),
3901
+ };
3902
+ return [
3903
+ docs.leading_comments,
3904
+ group([
3905
+ group([
3906
+ docs.self,
3907
+ docs.trailing_comments,
3908
+ p.has("not") ? " " : "",
3909
+ docs.not,
3910
+ " ",
3911
+ docs.matched,
3912
+ docs.by_target_or_source,
3913
+ p.has("and") ? " " : "",
3914
+ docs.and,
3915
+ " ",
3916
+ docs.then,
3917
+ ]),
3918
+ ]),
3919
+ ];
3920
+ };
3921
+ const printWhileStatement = (path, options, print, node) => {
3922
+ const p = new Printer(path, options, print, node);
3923
+ p.setBreakRecommended("condition"); // AND or OR
3924
+ p.setGroupRecommended("condition"); // other binary operator
3925
+ let leading_label_comments = "";
3926
+ if (node.children.leading_label &&
3927
+ node.children.leading_label.Node.children.leading_comments) {
3928
+ leading_label_comments =
3929
+ node.children.leading_label.Node.children.leading_comments.NodeVec.map((n) => [n.token.literal, hardline]);
3930
+ p.consumeLeadingCommentsOfX("leading_label");
3931
+ }
3932
+ const docs = {
3933
+ leading_label: p.child("leading_label"),
3934
+ colon: p.child("colon", undefined, "all"),
3935
+ leading_comments: printLeadingComments(path, options, print, node),
3936
+ self: p.self("upper"),
3937
+ trailing_comments: printTrailingComments(path, options, print, node),
3938
+ condition: p.child("condition"),
3939
+ do: p.child("do", undefined, "all"),
3940
+ end_while: group(p.child("end_while", undefined, "none", line)),
3941
+ trailing_label: p.child("trailing_label", undefined, "all"),
3942
+ semicolon: p.child("semicolon"),
3943
+ };
3944
+ return [
3945
+ leading_label_comments,
3946
+ docs.leading_comments,
3947
+ group([
3948
+ group([
3949
+ docs.leading_label,
3950
+ docs.colon,
3951
+ p.has("leading_label") ? " " : "",
3952
+ docs.self,
3953
+ docs.trailing_comments,
3954
+ indent([line, docs.condition]),
3955
+ ifBreak(line, " "),
3956
+ ]),
3957
+ docs.do,
3958
+ line,
3959
+ docs.end_while,
3960
+ p.has("trailing_label") ? " " : "",
3961
+ docs.trailing_label,
3962
+ softline,
3963
+ docs.semicolon,
3964
+ ]),
3965
+ p.newLine(),
3966
+ ];
3967
+ };
3968
+ const printWindowClause = (path, options, print, node) => {
3969
+ const p = new Printer(path, options, print, node);
3970
+ const docs = {
3971
+ leading_comments: printLeadingComments(path, options, print, node),
3972
+ self: p.self("upper"),
3973
+ trailing_comments: printTrailingComments(path, options, print, node),
3974
+ window_exprs: p.len("window_exprs") === 1
3975
+ ? p.child("window_exprs", (x) => [" ", group(x)], "all")
3976
+ : p.child("window_exprs", (x) => [line, group(x)]),
3977
+ };
3978
+ return [
3979
+ docs.leading_comments,
3980
+ docs.self,
3981
+ docs.trailing_comments,
3982
+ indent(docs.window_exprs),
3983
+ ];
3984
+ };
3985
+ const printWindowExpr = (path, options, print, node) => {
3986
+ const p = new Printer(path, options, print, node);
3987
+ const docs = {
3988
+ leading_comments: printLeadingComments(path, options, print, node),
3989
+ self: p.self(),
3990
+ trailing_comments: printTrailingComments(path, options, print, node),
3991
+ as: p.child("as", undefined, "all"),
3992
+ window: p.child("window", undefined, "all"),
3993
+ comma: p.child("comma", undefined, "all"),
3994
+ };
3995
+ return [
3996
+ docs.leading_comments,
3997
+ docs.self,
3998
+ docs.trailing_comments,
3999
+ " ",
4000
+ docs.as,
4001
+ " ",
4002
+ docs.window,
4003
+ docs.comma,
4004
+ ];
4005
+ };
4006
+ const printWindowFrameClause = (path, options, print, node) => {
4007
+ const p = new Printer(path, options, print, node);
4008
+ const docs = {
4009
+ leading_comments: printLeadingComments(path, options, print, node),
4010
+ self: p.self("upper"),
4011
+ trailing_comments: printTrailingComments(path, options, print, node),
4012
+ between: p.child("between", undefined, "all"),
4013
+ start: p.child("start", undefined, "none", line),
4014
+ and: p.child("and"),
4015
+ end: p.child("end", undefined, "all", line),
4016
+ };
4017
+ docs.leading_comments;
4018
+ return [
4019
+ docs.leading_comments,
4020
+ docs.self,
4021
+ docs.trailing_comments,
4022
+ p.has("between") ? [" ", docs.between] : "",
4023
+ indent([
4024
+ line,
4025
+ group(docs.start),
4026
+ p.has("and") ? [line, group([docs.and, " ", group(docs.end)])] : "",
4027
+ ]),
4028
+ ];
4029
+ };
4030
+ const printWindowSpecification = (path, options, print, node) => {
4031
+ const p = new Printer(path, options, print, node);
4032
+ const empty = !(p.has("name") ||
4033
+ p.has("partitionby") ||
4034
+ p.has("orderby") ||
4035
+ p.has("frame"));
4036
+ const docs = {
4037
+ leading_comments: "",
4038
+ self: p.self("upper", true),
4039
+ trailing_comments: printTrailingComments(path, options, print, node),
4040
+ name: p.child("name"),
4041
+ partitionby: p.child("partitionby", (x) => group(x)),
4042
+ orderby: p.child("orderby", (x) => group(x)),
4043
+ frame: p.child("frame", (x) => group(x)),
4044
+ rparen: p.child("rparen", undefined),
4045
+ };
4046
+ return [
4047
+ docs.self,
4048
+ docs.trailing_comments,
4049
+ indent([
4050
+ empty ? "" : softline,
4051
+ join(line, [docs.name, docs.partitionby, docs.orderby, docs.frame].filter((x) => x)),
4052
+ ]),
4053
+ empty ? "" : softline,
4054
+ docs.rparen,
4055
+ ];
4056
+ };
4057
+ const printWithClause = (path, options, print, node) => {
4058
+ const sep = options.printBlankLineAfterCte ? [hardline, hardline] : line;
4059
+ const p = new Printer(path, options, print, node);
4060
+ const docs = {
4061
+ leading_comments: printLeadingComments(path, options, print, node),
4062
+ self: p.self("upper"),
4063
+ trailing_comments: printTrailingComments(path, options, print, node),
4064
+ recursive: p.child("recursive", undefined, "all"),
4065
+ queries: p.len("queries") === 1 && !p.hasLeadingComments("queries")
4066
+ ? [" ", p.child("queries", undefined)]
4067
+ : options.indentCte
4068
+ ? indent([line, p.child("queries", undefined, "none", sep)])
4069
+ : [line, p.child("queries", undefined, "none", sep)],
4070
+ };
4071
+ return [
4072
+ docs.leading_comments,
4073
+ docs.self,
4074
+ p.has("recursive") ? " " : "",
4075
+ docs.recursive,
4076
+ docs.trailing_comments,
4077
+ docs.queries,
4078
+ ];
4079
+ };
4080
+ const printWithPartitionColumnsClause = (path, options, print, node) => {
4081
+ const p = new Printer(path, options, print, node);
4082
+ const docs = {
4083
+ leading_comments: printLeadingComments(path, options, print, node),
4084
+ self: p.self(),
4085
+ trailing_comments: printTrailingComments(path, options, print, node),
4086
+ partition_columns: p.child("partition_columns", (x) => group([line, x])),
4087
+ column_schema_group: p.child("column_schema_group", undefined, "all"),
4088
+ };
4089
+ return [
4090
+ docs.leading_comments,
4091
+ group([
4092
+ docs.self,
4093
+ docs.trailing_comments,
4094
+ docs.partition_columns,
4095
+ p.has("column_schema_group") ? " " : "",
4096
+ docs.column_schema_group,
4097
+ ]),
4098
+ ];
4099
+ };
4100
+ const printWithQuery = (path, options, print, node) => {
4101
+ const p = new Printer(path, options, print, node);
4102
+ p.setNotRoot("stmt");
4103
+ const docs = {
4104
+ leading_comments: printLeadingComments(path, options, print, node),
4105
+ self: p.self(),
4106
+ trailing_comments: printTrailingComments(path, options, print, node),
4107
+ as: p.child("as", undefined, "all"),
4108
+ stmt: p.child("stmt", undefined, "all"),
4109
+ comma: p.child("comma", undefined, "all"),
4110
+ };
4111
+ return [
4112
+ docs.leading_comments,
4113
+ docs.self,
4114
+ docs.trailing_comments,
4115
+ " ",
4116
+ docs.as,
4117
+ " ",
4118
+ docs.stmt,
4119
+ docs.comma,
4120
+ ];
4121
+ };
4122
+ const printXXXByExprs = (path, options, print, node) => {
4123
+ const p = new Printer(path, options, print, node);
4124
+ p.setGroupRecommended("exprs");
4125
+ const docs = {
4126
+ leading_comments: printLeadingComments(path, options, print, node),
4127
+ self: p.self("upper"),
4128
+ trailing_comments: printTrailingComments(path, options, print, node),
4129
+ by: p.child("by", undefined, "all"),
4130
+ exprs: indent(p.child("exprs", (x) => [line, x])),
4131
+ };
4132
+ return [
4133
+ docs.leading_comments,
4134
+ docs.self,
4135
+ docs.trailing_comments,
4136
+ " ",
4137
+ docs.by,
4138
+ node.children.exprs.NodeVec.every((x) => x.token.literal.match(/^[0-9]+$/)) || p.len("exprs") === 1
4139
+ ? group(docs.exprs)
4140
+ : docs.exprs,
4141
+ ];
4142
+ };
4143
+ // ----- utils -----
4144
+ const printAlias = (path, options, print, node) => {
4145
+ const p = new Printer(path, options, print, node);
4146
+ let as_;
4147
+ if (!p.has("alias")) {
4148
+ return "";
4149
+ }
4150
+ if (p.has("as")) {
4151
+ as_ = p.child("as", undefined, "all");
4152
+ }
4153
+ else {
4154
+ as_ = options.printKeywordsInUpperCase ? "AS" : "as";
4155
+ }
4156
+ return [" ", as_, " ", p.child("alias", undefined, "all")];
4157
+ };
4158
+ const printComma = (path, options, print, node) => {
4159
+ const p = new Printer(path, options, print, node);
4160
+ if (p.node.isFinalColumn) {
4161
+ return ifBreak(p.child("comma", undefined, "all") || ",", p.consumeAllCommentsOfX("comma"));
4162
+ }
4163
+ else {
4164
+ return p.child("comma", undefined, "all");
4165
+ }
4166
+ };
4167
+ const printLeadingComments = (path, options, print, node) => {
4168
+ const p = new Printer(path, options, print, node);
4169
+ return p.child("leading_comments", (x) => [x, hardline]);
4170
+ };
4171
+ const printOrder = (path, options, print, node) => {
4172
+ const p = new Printer(path, options, print, node);
4173
+ return [
4174
+ p.has("order") ? [" ", p.child("order", undefined, "all")] : "",
4175
+ p.has("null_order") ? p.child("null_order", (x) => group([line, x])) : "",
4176
+ ];
4177
+ };
4178
+ const printPivotOrUnpivotOperator = (path, options, print, node) => {
4179
+ const p = new Printer(path, options, print, node);
4180
+ const pivot = p.has("pivot") ? [" ", p.child("pivot", undefined, "all")] : "";
4181
+ const unpivot = p.has("unpivot")
4182
+ ? [" ", p.child("unpivot", undefined, "all")]
4183
+ : "";
4184
+ return [pivot, unpivot];
4185
+ };
4186
+ const printTrailingComments = (path, options, print, node) => {
4187
+ const p = new Printer(path, options, print, node);
4188
+ return lineSuffix(p.child("trailing_comments", (x) => [" ", x]));
4189
+ };
4190
+ //# sourceMappingURL=printer.js.map