-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathast.go
More file actions
4259 lines (3425 loc) · 101 KB
/
ast.go
File metadata and controls
4259 lines (3425 loc) · 101 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package ast provides AST nodes definitions.
//
// The definitions of ASTs are based on the following document.
//
// - https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language
// - https://cloud.google.com/spanner/docs/query-syntax
//
// Each Node's documentation describes its syntax (SQL representation) in a text/template
// fashion with thw following custom functions.
//
// - sql node: Returns the SQL representation of node.
// - sqlOpt node: Like sql node, but returns the empty string if node is nil.
// - sqlJoin sep nodes: Concatenates the SQL representations of nodes with sep.
// - sqlIdentQuote x: Quotes the given identifier string if needed.
// - sqlStringQuote s: Returns the SQL quoted string of s.
// - sqlBytesQuote bs: Returns the SQL quotes bytes of bs.
// - tokenJoin toks: Concateates the string representations of tokens.
// - isnil v: Checks whether v is nil or others.
//
// Each Node's documentation has pos and end information using the following EBNF.
//
// PosChoice -> PosExpr ("||" PosExpr)*
// PosExpr -> PosAtom ("+" IntAtom)*
// PosAtom -> PosVar | NodeExpr "." ("pos" | "end")
// NodeExpr -> NodeAtom | "(" NodeAtom ("??" NodeAtom)* ")"
// NodeAtom -> NodeVar | NodeSliceVar "[" (IntAtom | "$") "]"
// IntAtom -> IntVal
// | "len" "(" StringVar ")"
// | "(" BoolVar "?" IntAtom ":" IntAtom ")"
// IntVal -> "0" | "1" | ...
//
// (PosVar, NodeVar, NodeSliceVar, and BoolVar are derived by its struct definition.)
package ast
// NOTE: ast.go and ast_*.go are used for automatic generation, so these files are conventional.
// NOTE: This file defines AST nodes and they are used for automatic generation,
// so this file is conventional.
//
// Conventions:
//
// - Each node interface (except for Node) must have isXXX method (XXX is a name of the interface itself).
// - `isXXX` methods must be defined after the interface definition
// and the receiver must be the non-pointer node struct type.
// - Each node struct must have pos and end comments.
// - Each node struct must have template lines in its doc comment.
// - The fields of each node must be ordered by the position.
//go:generate go run ../tools/gen-ast-pos/main.go -astfile ast.go -constfile ast_const.go -outfile pos.go
import (
"github.com/cloudspannerecosystem/memefish/token"
)
// Node is base interface of Spanner SQL AST nodes.
type Node interface {
Pos() token.Pos
End() token.Pos
// Convert AST node into SQL source string (a.k.a. Unparse).
SQL() string
}
// Statement represents toplevel statement node of Spanner SQL.
type Statement interface {
Node
isStatement()
}
// The order of this list follows the official documentation:
//
// - https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language
// - https://cloud.google.com/spanner/docs/reference/standard-sql/dml-syntax
func (BadStatement) isStatement() {}
func (BadDDL) isStatement() {}
func (BadDML) isStatement() {}
func (QueryStatement) isStatement() {}
func (CreateSchema) isStatement() {}
func (DropSchema) isStatement() {}
func (CreateDatabase) isStatement() {}
func (AlterDatabase) isStatement() {}
func (CreateLocalityGroup) isStatement() {}
func (AlterLocalityGroup) isStatement() {}
func (DropLocalityGroup) isStatement() {}
func (CreatePlacement) isStatement() {}
func (CreateProtoBundle) isStatement() {}
func (AlterProtoBundle) isStatement() {}
func (DropProtoBundle) isStatement() {}
func (CreateTable) isStatement() {}
func (AlterTable) isStatement() {}
func (DropTable) isStatement() {}
func (RenameTable) isStatement() {}
func (CreateIndex) isStatement() {}
func (AlterIndex) isStatement() {}
func (DropIndex) isStatement() {}
func (CreateSearchIndex) isStatement() {}
func (DropSearchIndex) isStatement() {}
func (AlterSearchIndex) isStatement() {}
func (CreateView) isStatement() {}
func (DropView) isStatement() {}
func (CreateChangeStream) isStatement() {}
func (AlterChangeStream) isStatement() {}
func (DropChangeStream) isStatement() {}
func (CreateRole) isStatement() {}
func (DropRole) isStatement() {}
func (Grant) isStatement() {}
func (Revoke) isStatement() {}
func (CreateSequence) isStatement() {}
func (AlterSequence) isStatement() {}
func (DropSequence) isStatement() {}
func (AlterStatistics) isStatement() {}
func (CreateModel) isStatement() {}
func (AlterModel) isStatement() {}
func (DropModel) isStatement() {}
func (Analyze) isStatement() {}
func (CreateVectorIndex) isStatement() {}
func (AlterVectorIndex) isStatement() {}
func (DropVectorIndex) isStatement() {}
func (CreatePropertyGraph) isStatement() {}
func (DropPropertyGraph) isStatement() {}
func (Insert) isStatement() {}
func (Delete) isStatement() {}
func (Update) isStatement() {}
func (Call) isStatement() {}
// QueryExpr represents query expression, which can be body of QueryStatement or subqueries.
// Select and FromQuery are leaf QueryExpr and others wrap other QueryExpr.
type QueryExpr interface {
Node
isQueryExpr()
}
func (BadQueryExpr) isQueryExpr() {}
func (Select) isQueryExpr() {}
func (Query) isQueryExpr() {}
func (FromQuery) isQueryExpr() {}
func (SubQuery) isQueryExpr() {}
func (CompoundQuery) isQueryExpr() {}
// PipeOperator represents pipe operator node which can be appeared in Query.
type PipeOperator interface {
Node
isPipeOperator()
}
func (PipeSelect) isPipeOperator() {}
func (PipeWhere) isPipeOperator() {}
// SelectItem represents expression in SELECT clause result columns list.
type SelectItem interface {
Node
isSelectItem()
}
func (Star) isSelectItem() {}
func (DotStar) isSelectItem() {}
func (Alias) isSelectItem() {}
func (ExprSelectItem) isSelectItem() {}
// SelectAs represents AS VALUE/STRUCT/typename clause in SELECT clause.
type SelectAs interface {
Node
isSelectAs()
}
func (AsStruct) isSelectAs() {}
func (AsValue) isSelectAs() {}
func (AsTypeName) isSelectAs() {}
// TableExpr represents JOIN operands.
type TableExpr interface {
Node
isTableExpr()
}
func (Unnest) isTableExpr() {}
func (TableName) isTableExpr() {}
func (PathTableExpr) isTableExpr() {}
func (SubQueryTableExpr) isTableExpr() {}
func (ParenTableExpr) isTableExpr() {}
func (Join) isTableExpr() {}
func (TVFCallExpr) isTableExpr() {}
// JoinCondition represents condition part of JOIN expression.
type JoinCondition interface {
Node
isJoinCondition()
}
func (On) isJoinCondition() {}
func (Using) isJoinCondition() {}
// Expr repersents an expression in SQL.
type Expr interface {
Node
isExpr()
}
func (BadExpr) isExpr() {}
func (BinaryExpr) isExpr() {}
func (UnaryExpr) isExpr() {}
func (InExpr) isExpr() {}
func (IsNullExpr) isExpr() {}
func (IsBoolExpr) isExpr() {}
func (BetweenExpr) isExpr() {}
func (SelectorExpr) isExpr() {}
func (IndexExpr) isExpr() {}
func (CallExpr) isExpr() {}
func (CountStarExpr) isExpr() {}
func (CastExpr) isExpr() {}
func (ExtractExpr) isExpr() {}
func (WithExpr) isExpr() {}
func (ReplaceFieldsExpr) isExpr() {}
func (CaseExpr) isExpr() {}
func (IfExpr) isExpr() {}
func (ParenExpr) isExpr() {}
func (ScalarSubQuery) isExpr() {}
func (ArraySubQuery) isExpr() {}
func (ExistsSubQuery) isExpr() {}
func (Param) isExpr() {}
func (Ident) isExpr() {}
func (Path) isExpr() {}
func (ArrayLiteral) isExpr() {}
func (TupleStructLiteral) isExpr() {}
func (TypelessStructLiteral) isExpr() {}
func (TypedStructLiteral) isExpr() {}
func (NullLiteral) isExpr() {}
func (BoolLiteral) isExpr() {}
func (IntLiteral) isExpr() {}
func (FloatLiteral) isExpr() {}
func (StringLiteral) isExpr() {}
func (BytesLiteral) isExpr() {}
func (DateLiteral) isExpr() {}
func (TimestampLiteral) isExpr() {}
func (NumericLiteral) isExpr() {}
func (JSONLiteral) isExpr() {}
func (IntervalLiteralSingle) isExpr() {}
func (IntervalLiteralRange) isExpr() {}
func (NewConstructor) isExpr() {}
func (BracedNewConstructor) isExpr() {}
func (BracedConstructor) isExpr() {}
// SubscriptSpecifier represents specifier of subscript operators.
type SubscriptSpecifier interface {
Node
isSubscriptSpecifier()
}
func (ExprArg) isSubscriptSpecifier() {}
func (SubscriptSpecifierKeyword) isSubscriptSpecifier() {}
// Arg represents argument of function call.
type Arg interface {
Node
isArg()
}
func (ExprArg) isArg() {}
func (SequenceArg) isArg() {}
func (LambdaArg) isArg() {}
type TVFArg interface {
Node
isTVFArg()
}
func (ExprArg) isTVFArg() {}
func (ModelArg) isTVFArg() {}
func (TableArg) isTVFArg() {}
// NullHandlingModifier represents IGNORE/RESPECT NULLS of aggregate function calls
type NullHandlingModifier interface {
Node
isNullHandlingModifier()
}
func (IgnoreNulls) isNullHandlingModifier() {}
func (RespectNulls) isNullHandlingModifier() {}
// HavingModifier represents HAVING clause of aggregate function calls.
type HavingModifier interface {
Node
isHavingModifier()
}
func (HavingMax) isHavingModifier() {}
func (HavingMin) isHavingModifier() {}
// InCondition is right-side value of IN operator.
type InCondition interface {
Node
isInCondition()
}
func (UnnestInCondition) isInCondition() {}
func (SubQueryInCondition) isInCondition() {}
func (ValuesInCondition) isInCondition() {}
// TypelessStructLiteralArg represents an argument of typeless STRUCT literals.
type TypelessStructLiteralArg interface {
Node
isTypelessStructLiteralArg()
}
func (ExprArg) isTypelessStructLiteralArg() {}
func (Alias) isTypelessStructLiteralArg() {}
// NewConstructorArg represents an argument of NEW constructors.
type NewConstructorArg interface {
Node
isNewConstructorArg()
}
func (ExprArg) isNewConstructorArg() {}
func (Alias) isNewConstructorArg() {}
// Type represents type node.
type Type interface {
Node
isType()
}
func (BadType) isType() {}
func (SimpleType) isType() {}
func (ArrayType) isType() {}
func (StructType) isType() {}
func (NamedType) isType() {}
// IntValue represents integer values in SQL.
type IntValue interface {
Node
isIntValue()
}
func (Param) isIntValue() {}
func (IntLiteral) isIntValue() {}
func (CastIntValue) isIntValue() {}
// NumValue represents number values in SQL.
type NumValue interface {
Node
isNumValue()
}
func (Param) isNumValue() {}
func (IntLiteral) isNumValue() {}
func (FloatLiteral) isNumValue() {}
func (CastNumValue) isNumValue() {}
// StringValue represents string value in SQL.
type StringValue interface {
Node
isStringValue()
}
func (Param) isStringValue() {}
func (StringLiteral) isStringValue() {}
// DDL represents data definition language in SQL.
//
// https://cloud.google.com/spanner/docs/data-definition-language
type DDL interface {
Statement
isDDL()
}
// The order of this list follows the official documentation:
//
// - https://cloud.google.com/spanner/docs/reference/standard-sql/data-definition-language
func (BadDDL) isDDL() {}
func (CreateSchema) isDDL() {}
func (DropSchema) isDDL() {}
func (CreateDatabase) isDDL() {}
func (AlterDatabase) isDDL() {}
func (CreateLocalityGroup) isDDL() {}
func (AlterLocalityGroup) isDDL() {}
func (DropLocalityGroup) isDDL() {}
func (CreatePlacement) isDDL() {}
func (CreateProtoBundle) isDDL() {}
func (AlterProtoBundle) isDDL() {}
func (DropProtoBundle) isDDL() {}
func (CreateTable) isDDL() {}
func (AlterTable) isDDL() {}
func (DropTable) isDDL() {}
func (RenameTable) isDDL() {}
func (CreateIndex) isDDL() {}
func (AlterIndex) isDDL() {}
func (DropIndex) isDDL() {}
func (CreateView) isDDL() {}
func (CreateSearchIndex) isDDL() {}
func (DropSearchIndex) isDDL() {}
func (AlterSearchIndex) isDDL() {}
func (DropView) isDDL() {}
func (CreateChangeStream) isDDL() {}
func (AlterChangeStream) isDDL() {}
func (DropChangeStream) isDDL() {}
func (CreateRole) isDDL() {}
func (DropRole) isDDL() {}
func (Grant) isDDL() {}
func (Revoke) isDDL() {}
func (CreateSequence) isDDL() {}
func (AlterSequence) isDDL() {}
func (DropSequence) isDDL() {}
func (AlterStatistics) isDDL() {}
func (CreateModel) isDDL() {}
func (AlterModel) isDDL() {}
func (DropModel) isDDL() {}
func (Analyze) isDDL() {}
func (CreateVectorIndex) isDDL() {}
func (AlterVectorIndex) isDDL() {}
func (DropVectorIndex) isDDL() {}
func (CreatePropertyGraph) isDDL() {}
func (DropPropertyGraph) isDDL() {}
// Constraint represents table constraint of CONSTARINT clause.
type Constraint interface {
Node
isConstraint()
}
func (ForeignKey) isConstraint() {}
func (Check) isConstraint() {}
// TableAlteration represents ALTER TABLE action.
type TableAlteration interface {
Node
isTableAlteration()
}
func (AddSynonym) isTableAlteration() {}
func (DropSynonym) isTableAlteration() {}
func (RenameTo) isTableAlteration() {}
func (AddColumn) isTableAlteration() {}
func (AddTableConstraint) isTableAlteration() {}
func (AddRowDeletionPolicy) isTableAlteration() {}
func (DropColumn) isTableAlteration() {}
func (DropConstraint) isTableAlteration() {}
func (DropRowDeletionPolicy) isTableAlteration() {}
func (ReplaceRowDeletionPolicy) isTableAlteration() {}
func (SetOnDelete) isTableAlteration() {}
func (SetInterleaveIn) isTableAlteration() {}
func (AlterColumn) isTableAlteration() {}
func (AlterTableSetOptions) isTableAlteration() {}
// ColumnDefaultSemantics is interface of DefaultExpr, GeneratedColumnExpr, IdentityColumn, AutoIncrement.
// They are change default value of column and mutually exclusive.
type ColumnDefaultSemantics interface {
Node
isColumnDefaultSemantics()
}
func (ColumnDefaultExpr) isColumnDefaultSemantics() {}
func (GeneratedColumnExpr) isColumnDefaultSemantics() {}
func (IdentityColumn) isColumnDefaultSemantics() {}
func (AutoIncrement) isColumnDefaultSemantics() {}
type SequenceParam interface {
Node
isSequenceParam()
}
func (BitReversedPositive) isSequenceParam() {}
func (SkipRange) isSequenceParam() {}
func (StartCounterWith) isSequenceParam() {}
// ColumnAlteration represents ALTER COLUMN action in ALTER TABLE.
type ColumnAlteration interface {
Node
isColumnAlteration()
}
func (AlterColumnType) isColumnAlteration() {}
func (AlterColumnSetOptions) isColumnAlteration() {}
func (AlterColumnSetDefault) isColumnAlteration() {}
func (AlterColumnDropDefault) isColumnAlteration() {}
func (AlterColumnAlterIdentity) isColumnAlteration() {}
type IdentityAlteration interface {
Node
isIdentityAlteration()
}
func (RestartCounterWith) isIdentityAlteration() {}
func (SetSkipRange) isIdentityAlteration() {}
func (SetNoSkipRange) isIdentityAlteration() {}
// Privilege represents privileges specified by GRANT and REVOKE.
type Privilege interface {
Node
isPrivilege()
}
func (PrivilegeOnTable) isPrivilege() {}
func (SelectPrivilegeOnChangeStream) isPrivilege() {}
func (SelectPrivilegeOnView) isPrivilege() {}
func (ExecutePrivilegeOnTableFunction) isPrivilege() {}
func (RolePrivilege) isPrivilege() {}
// TablePrivilege represents privileges on table.
type TablePrivilege interface {
Node
isTablePrivilege()
}
func (SelectPrivilege) isTablePrivilege() {}
func (InsertPrivilege) isTablePrivilege() {}
func (UpdatePrivilege) isTablePrivilege() {}
func (DeletePrivilege) isTablePrivilege() {}
// SchemaType represents types for schema.
type SchemaType interface {
Node
isSchemaType()
}
func (ScalarSchemaType) isSchemaType() {}
func (SizedSchemaType) isSchemaType() {}
func (ArraySchemaType) isSchemaType() {}
func (NamedType) isSchemaType() {}
// IndexAlteration represents ALTER INDEX action.
type IndexAlteration interface {
Node
isIndexAlteration()
}
func (AddStoredColumn) isIndexAlteration() {}
func (DropStoredColumn) isIndexAlteration() {}
// VectorIndexAlteration represents ALTER VECTOR INDEX action.
// Note: Currently, it is same as IndexAlteration,
// but cloud-spanner-emulator/backend/schema/parser/ddl_parser.jjt implies their difference.
type VectorIndexAlteration interface {
Node
isVectorIndexAlteration()
}
func (AddStoredColumn) isVectorIndexAlteration() {}
func (DropStoredColumn) isVectorIndexAlteration() {}
// DML represents data manipulation language in SQL.
//
// https://cloud.google.com/spanner/docs/data-definition-language
type DML interface {
Statement
isDML()
}
func (BadDML) isDML() {}
func (Insert) isDML() {}
func (Delete) isDML() {}
func (Update) isDML() {}
// InsertInput represents input values of INSERT statement.
type InsertInput interface {
Node
isInsertInput()
}
func (ValuesInput) isInsertInput() {}
func (SubQueryInput) isInsertInput() {}
// ChangeStreamFor represents FOR clause in CREATE/ALTER CHANGE STREAM statement.
type ChangeStreamFor interface {
Node
isChangeStreamFor()
}
func (ChangeStreamForAll) isChangeStreamFor() {}
func (ChangeStreamForTables) isChangeStreamFor() {}
// ChangeStreamAlteration represents ALTER CHANGE STREAM action.
type ChangeStreamAlteration interface {
Node
isChangeStreamAlteration()
}
func (ChangeStreamSetFor) isChangeStreamAlteration() {}
func (ChangeStreamDropForAll) isChangeStreamAlteration() {}
func (ChangeStreamSetOptions) isChangeStreamAlteration() {}
// ================================================================================
//
// Bad Node
//
// ================================================================================
// BadNode is a placeholder node for a source code containing syntax errors.
//
// {{.Tokens | tokenJoin}}
type BadNode struct {
// pos = NodePos
// end = NodeEnd
NodePos, NodeEnd token.Pos
Tokens []*token.Token
}
// BadStatement is a BadNode for Statement.
//
// {{.Hint | sqlOpt}} {{.BadNode | sql}}
type BadStatement struct {
// pos = (Hint ?? BadNode).pos
// end = BadNode.end
Hint *Hint
BadNode *BadNode
}
// BadQueryExpr is a BadNode for QueryExpr.
//
// {{.BadNode | sql}}
type BadQueryExpr struct {
// pos = BadNode.pos
// end = BadNode.end
Hint *Hint
BadNode *BadNode
}
// BadExpr is a BadNode for Expr.
//
// {{.BadNode | sql}}
type BadExpr struct {
// pos = BadNode.pos
// end = BadNode.end
BadNode *BadNode
}
// BadType is a BadNode for Type.
//
// {{.BadNode | sql}}
type BadType struct {
// pos = BadNode.pos
// end = BadNode.end
BadNode *BadNode
}
// BadDDL is a BadNode for DDL.
//
// {{.BadNode | sql}}
type BadDDL struct {
// pos = BadNode.pos
// end = BadNode.end
BadNode *BadNode
}
// BadDML is a BadNode for DML.
//
// {{.Hint | sqlOpt}} {{.BadNode | sql}}
type BadDML struct {
// pos = (Hint ?? BadNode).pos
// end = BadNode.end
Hint *Hint // optional
BadNode *BadNode
}
// ================================================================================
//
// SELECT
//
// ================================================================================
// QueryStatement is query statement node.
//
// {{.Hint | sqlOpt}} {{.Query | sql}}
type QueryStatement struct {
// pos = (Hint ?? Query).pos
// end = Query.end
Hint *Hint // optional
Query QueryExpr
}
// Query is query expression node with optional CTE, ORDER BY, LIMIT, and pipe operators.
// Usually, it is used as outermost QueryExpr in SubQuery and QueryStatement
//
// {{.With | sqlOpt}}
// {{.Query | sql}}
// {{.OrderBy | sqlOpt}}
// {{.Limit | sqlOpt}}
// {{.PipeOperators | sqlJoin ", "}}
//
// https://cloud.google.com/spanner/docs/query-syntax
type Query struct {
// pos = (With ?? Query).pos
// end = (PipeOperators[$] ?? ForUpdate ?? Limit ?? OrderBy ?? Query).end
With *With
Query QueryExpr
OrderBy *OrderBy // optional
Limit *Limit // optional
ForUpdate *ForUpdate // optional
PipeOperators []PipeOperator
}
// ForUpdate is FOR UPDATE node.
//
// FOR UPDATE
type ForUpdate struct {
// pos = For
// end = Update + 6
For, Update token.Pos
}
// Hint is hint node.
//
// @{{"{"}}{{.Records | sqlJoin ","}}{{"}"}}
type Hint struct {
// pos = Atmark
// end = Rbrace + 1
Atmark token.Pos // position of "@"
Rbrace token.Pos // position of "}"
Records []*HintRecord // len(Records) > 0
}
// HintRecord is hint record node.
//
// {{.Key | sql}}={{.Value | sql}}
type HintRecord struct {
// pos = Key.pos
// end = Value.end
Key *Path
Value Expr
}
// With is with clause node.
//
// WITH {{.CTEs | sqlJoin ","}}
type With struct {
// pos = With
// end = CTEs[$].end
With token.Pos // position of "WITH" keyword
CTEs []*CTE
}
// CTE is common table expression node.
//
// {{.Name}} AS ({{.QueryExpr}})
type CTE struct {
// pos = Name.pos
// end = Rparen + 1
Rparen token.Pos // position of ")"
Name *Ident
QueryExpr QueryExpr
}
// Select is SELECT statement node.
//
// SELECT
// {{.AllOrDistinct}}
// {{.As | sqlOpt}}
// {{.Results | sqlJoin ","}}
// {{.From | sqlOpt}}
// {{.Where | sqlOpt}}
// {{.GroupBy | sqlOpt}}
// {{.Having | sqlOpt}}
type Select struct {
// pos = Select
// end = (Having ?? GroupBy ?? Where ?? From ?? Results[$]).end
Select token.Pos // position of "select" keyword
AllOrDistinct AllOrDistinct // optional
As SelectAs // optional
Results []SelectItem // len(Results) > 0
From *From // optional
Where *Where // optional
GroupBy *GroupBy // optional
Having *Having // optional
}
// AsStruct represents AS STRUCT node in SELECT clause.
//
// AS STRUCT
type AsStruct struct {
// pos = As
// end = Struct + 6
As token.Pos
Struct token.Pos
}
// AsValue represents AS VALUE node in SELECT clause.
//
// AS VALUE
type AsValue struct {
// pos = As
// end = Value + 5
As token.Pos
Value token.Pos
}
// AsTypeName represents AS typename node in SELECT clause.
//
// AS {{.TypeName | sql}}
type AsTypeName struct {
// pos = As
// end = TypeName.end
As token.Pos
TypeName *NamedType
}
// FromQuery is FROM query expression node.
//
// FROM {{.From | sql}}
type FromQuery struct {
// pos = From.pos
// end = From.end
From *From
}
// CompoundQuery is query expression node compounded by set operators.
// Note: A single CompoundQuery can express query expressions compounded by the same set operator.
// If there are mixed Op or Distinct in query expression, CompoundQuery will be nested.
//
// {{.Queries | sqlJoin (printf "%s %s" .Op .AllOrDistinct)}}
type CompoundQuery struct {
// pos = Queries[0].pos
// end = Queries[$].end
Op SetOp
AllOrDistinct AllOrDistinct
Queries []QueryExpr // len(Queries) >= 2
}
// SubQuery is parenthesized query expression node.
// Note: subquery expression is expressed as a ParenTableExpr. Maybe better to rename as like ParenQueryExpr?
//
// ({{.Query | sql}})
type SubQuery struct {
// pos = Lparen
// end = Rparen + 1
Lparen, Rparen token.Pos // position of "(" and ")"
Query QueryExpr
}
// StarModifierExcept is EXCEPT node in Star and DotStar of SelectItem.
//
// EXCEPT ({{Columns | sqlJoin ", "}})
type StarModifierExcept struct {
// pos = Except
// end = Rparen + 1
Except token.Pos
Rparen token.Pos
Columns []*Ident
}
// StarModifierReplaceItem is a single item of StarModifierReplace.
//
// {{.Expr | sql}} AS {{.Name | sql}}
type StarModifierReplaceItem struct {
// pos = Expr.pos
// end = Name.end
Expr Expr
Name *Ident
}
// StarModifierReplace is REPLACE node in Star and DotStar of SelectItem.
//
// REPLACE ({{Columns | sqlJoin ", "}})
type StarModifierReplace struct {
// pos = Replace
// end = Rparen + 1
Replace token.Pos
Rparen token.Pos
Columns []*StarModifierReplaceItem
}
// Star is a single * in SELECT result columns list.
//
// {{"*"}} {{.Except | sqlOpt}} {{.Replace | sqlOpt}}
//
// Note: The text/template notation escapes * to avoid normalize * to - by some formatters
// because the prefix * is ambiguous with bulletin list.
type Star struct {
// pos = Star
// end = (Replace ?? Except).end || Star + 1
Star token.Pos // position of "*"
Except *StarModifierExcept // optional
Replace *StarModifierReplace // optional
}
// DotStar is expression with * in SELECT result columns list.
//
// {{.Expr | sql}}.* {{.Except | sqlOpt}} {{.Replace | sqlOpt}}
type DotStar struct {
// pos = Expr.pos
// end = (Replace ?? Except).end || Star + 1
Star token.Pos // position of "*"
Expr Expr
Except *StarModifierExcept // optional
Replace *StarModifierReplace // optional
}
// Alias is aliased expression by AS clause.
//
// Typically, this appears in SELECT result columns list, but this can appear in typeless STRUCT literals
// and NEW constructors.
//
// {{.Expr | sql}} {{.As | sql}}
type Alias struct {
// pos = Expr.pos
// end = As.end
Expr Expr
As *AsAlias
}
// AsAlias is AS clause node for general purpose.
//
// It is used in Alias node and some JoinExpr nodes.
//
// {{if not .As.Invalid}}AS {{end}}{{.Alias | sql}}
type AsAlias struct {
// pos = As || Alias.pos
// end = Alias.end
As token.Pos // position of "AS" keyword, optional
Alias *Ident
}
// ExprSelectItem is Expr wrapper for SelectItem.
//
// {{.Expr | sql}}
type ExprSelectItem struct {
// pos = Expr.pos
// end = Expr.end
Expr Expr
}
// From is FROM clause node.
//
// FROM {{.Source | sql}}
type From struct {
// pos = From
// end = Source.end
From token.Pos // position of "FROM" keyword
Source TableExpr
}
// Where is WHERE clause node.
//
// WHERE {{.Expr | sql}}
type Where struct {
// pos = Where
// end = Expr.end
Where token.Pos // position of "WHERE" keyword
Expr Expr
}
// GroupBy is GROUP BY clause node.
//
// GROUP BY {{.Exprs | sqlJoin ","}}
type GroupBy struct {
// pos = Group
// end = Exprs[$].end
Group token.Pos // position of "GROUP" keyword
Exprs []Expr // len(Exprs) > 0
}
// Having is HAVING clause node.