Skip to content

Commit 9d8f3d5

Browse files
harshit-gangalsystayGuptaManan100frouioui
authored
VALUES statement AST and parsing (#17500)
Signed-off-by: Harshit Gangal <harshit@planetscale.com> Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr> Signed-off-by: Andres Taylor <andres@planetscale.com> Signed-off-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Andres Taylor <andres@planetscale.com> Co-authored-by: Manan Gupta <manan@planetscale.com> Co-authored-by: Florent Poinsard <florent.poinsard@outlook.fr>
1 parent fd0ffeb commit 9d8f3d5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+11364
-10723
lines changed

go/test/endtoend/vtgate/queries/random/query_gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type (
4646

4747
// queryGenerator generates queries, which can either be unions or select statements
4848
queryGenerator struct {
49-
stmt sqlparser.SelectStatement
49+
stmt sqlparser.TableStatement
5050
selGen *selectGenerator
5151
}
5252

go/test/endtoend/vtgate/queries/random/simplifier_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ func simplifyResultsMismatchedQuery(t *testing.T, query string) string {
100100
require.NoError(t, err)
101101

102102
simplified := simplifier.SimplifyStatement(
103-
stmt.(sqlparser.SelectStatement),
103+
stmt.(sqlparser.TableStatement),
104104
vSchemaWrapper.CurrentDb(),
105105
vSchemaWrapper,
106-
func(statement sqlparser.SelectStatement) bool {
106+
func(statement sqlparser.TableStatement) bool {
107107
q := sqlparser.String(statement)
108108
_, newErr := mcmp.ExecAllowAndCompareError(q, utils.CompareOptions{})
109109
if newErr == nil {

go/test/vschemawrapper/vschema_wrapper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (vw *VSchemaWrapper) FindTable(tab sqlparser.TableName) (*vindexes.Table, s
265265
return table, destKeyspace, destTabletType, destTarget, nil
266266
}
267267

268-
func (vw *VSchemaWrapper) FindView(tab sqlparser.TableName) sqlparser.SelectStatement {
268+
func (vw *VSchemaWrapper) FindView(tab sqlparser.TableName) sqlparser.TableStatement {
269269
destKeyspace, _, _, err := topoproto.ParseDestination(tab.Qualifier.String(), topodatapb.TabletType_PRIMARY)
270270
if err != nil {
271271
return nil

go/vt/proto/query/query.pb.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/schemadiff/view.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,6 @@ func (c *CreateViewEntity) identicalOtherThanName(other *CreateViewEntity) bool
427427
c.IsReplace == other.IsReplace &&
428428
sqlparser.Equals.RefOfDefiner(c.Definer, other.Definer) &&
429429
sqlparser.Equals.Columns(c.Columns, other.Columns) &&
430-
sqlparser.Equals.SelectStatement(c.Select, other.Select) &&
430+
sqlparser.Equals.Statement(c.Select, other.Select) &&
431431
sqlparser.Equals.RefOfParsedComments(c.Comments, other.Comments)
432432
}

go/vt/sqlparser/ast.go

Lines changed: 112 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,49 @@ type (
5757
OrderAndLimit interface {
5858
AddOrder(*Order)
5959
SetLimit(*Limit)
60+
GetOrderBy() OrderBy
61+
SetOrderBy(OrderBy)
62+
GetLimit() *Limit
63+
}
64+
65+
TableStatement interface {
66+
iTableStatement()
67+
68+
InsertRows
69+
Statement
70+
OrderAndLimit
71+
Commented
72+
ColumnResults
73+
Withable
74+
}
75+
76+
ColumnResults interface {
77+
GetColumnCount() int
78+
GetColumns() SelectExprs
79+
}
80+
81+
Withable interface {
82+
SetWith(with *With)
83+
}
84+
85+
Distinctable interface {
86+
MakeDistinct()
87+
IsDistinct() bool
6088
}
6189

6290
// SelectStatement any SELECT statement.
6391
SelectStatement interface {
6492
Statement
6593
InsertRows
6694
OrderAndLimit
95+
Commented
96+
ColumnResults
97+
Withable
98+
Distinctable
6799
iSelectStatement()
68100
GetLock() Lock
69101
SetLock(lock Lock)
70102
SetInto(into *SelectInto)
71-
SetWith(with *With)
72-
MakeDistinct()
73-
GetColumnCount() int
74-
GetColumns() SelectExprs
75-
Commented
76-
IsDistinct() bool
77-
GetOrderBy() OrderBy
78-
SetOrderBy(OrderBy)
79-
GetLimit() *Limit
80103
}
81104

82105
// DDLStatement represents any DDL Statement
@@ -161,7 +184,7 @@ type (
161184
CommonTableExpr struct {
162185
ID IdentifierCS
163186
Columns Columns
164-
Subquery SelectStatement
187+
Subquery TableStatement
165188
}
166189
// ChangeColumn is used to change the column definition, can also rename the column in alter table command
167190
ChangeColumn struct {
@@ -303,8 +326,8 @@ type (
303326
// Union represents a UNION statement.
304327
Union struct {
305328
With *With
306-
Left SelectStatement
307-
Right SelectStatement
329+
Left TableStatement
330+
Right TableStatement
308331
Distinct bool
309332
OrderBy OrderBy
310333
Limit *Limit
@@ -543,7 +566,7 @@ type (
543566
Definer *Definer
544567
Security string
545568
Columns Columns
546-
Select SelectStatement
569+
Select TableStatement
547570
CheckOption string
548571
IsReplace bool
549572
Comments *ParsedComments
@@ -556,7 +579,7 @@ type (
556579
Definer *Definer
557580
Security string
558581
Columns Columns
559-
Select SelectStatement
582+
Select TableStatement
560583
CheckOption string
561584
Comments *ParsedComments
562585
}
@@ -727,58 +750,63 @@ type (
727750
var _ OrderAndLimit = (*Select)(nil)
728751
var _ OrderAndLimit = (*Update)(nil)
729752
var _ OrderAndLimit = (*Delete)(nil)
730-
731-
func (*Union) iStatement() {}
732-
func (*Select) iStatement() {}
733-
func (*Stream) iStatement() {}
734-
func (*VStream) iStatement() {}
735-
func (*Insert) iStatement() {}
736-
func (*Update) iStatement() {}
737-
func (*Delete) iStatement() {}
738-
func (*Set) iStatement() {}
739-
func (*DropDatabase) iStatement() {}
740-
func (*Flush) iStatement() {}
741-
func (*Show) iStatement() {}
742-
func (*Use) iStatement() {}
743-
func (*Begin) iStatement() {}
744-
func (*Commit) iStatement() {}
745-
func (*Rollback) iStatement() {}
746-
func (*SRollback) iStatement() {}
747-
func (*Savepoint) iStatement() {}
748-
func (*Release) iStatement() {}
749-
func (*Analyze) iStatement() {}
750-
func (*OtherAdmin) iStatement() {}
751-
func (*CommentOnly) iStatement() {}
752-
func (*Select) iSelectStatement() {}
753-
func (*Union) iSelectStatement() {}
754-
func (*Load) iStatement() {}
755-
func (*CreateDatabase) iStatement() {}
756-
func (*AlterDatabase) iStatement() {}
757-
func (*CreateTable) iStatement() {}
758-
func (*CreateView) iStatement() {}
759-
func (*AlterView) iStatement() {}
760-
func (*LockTables) iStatement() {}
761-
func (*UnlockTables) iStatement() {}
762-
func (*AlterTable) iStatement() {}
763-
func (*AlterVschema) iStatement() {}
764-
func (*AlterMigration) iStatement() {}
765-
func (*RevertMigration) iStatement() {}
766-
func (*ShowMigrationLogs) iStatement() {}
767-
func (*ShowThrottledApps) iStatement() {}
768-
func (*ShowThrottlerStatus) iStatement() {}
769-
func (*DropTable) iStatement() {}
770-
func (*DropView) iStatement() {}
771-
func (*TruncateTable) iStatement() {}
772-
func (*RenameTable) iStatement() {}
773-
func (*CallProc) iStatement() {}
774-
func (*ExplainStmt) iStatement() {}
775-
func (*VExplainStmt) iStatement() {}
776-
func (*ExplainTab) iStatement() {}
777-
func (*PrepareStmt) iStatement() {}
778-
func (*ExecuteStmt) iStatement() {}
779-
func (*DeallocateStmt) iStatement() {}
780-
func (*PurgeBinaryLogs) iStatement() {}
781-
func (*Kill) iStatement() {}
753+
var _ OrderAndLimit = (*ValuesStatement)(nil)
754+
755+
func (*Union) iStatement() {}
756+
func (*Select) iStatement() {}
757+
func (*ValuesStatement) iStatement() {}
758+
func (*Stream) iStatement() {}
759+
func (*VStream) iStatement() {}
760+
func (*Insert) iStatement() {}
761+
func (*Update) iStatement() {}
762+
func (*Delete) iStatement() {}
763+
func (*Set) iStatement() {}
764+
func (*DropDatabase) iStatement() {}
765+
func (*Flush) iStatement() {}
766+
func (*Show) iStatement() {}
767+
func (*Use) iStatement() {}
768+
func (*Begin) iStatement() {}
769+
func (*Commit) iStatement() {}
770+
func (*Rollback) iStatement() {}
771+
func (*SRollback) iStatement() {}
772+
func (*Savepoint) iStatement() {}
773+
func (*Release) iStatement() {}
774+
func (*Analyze) iStatement() {}
775+
func (*OtherAdmin) iStatement() {}
776+
func (*CommentOnly) iStatement() {}
777+
func (*Select) iSelectStatement() {}
778+
func (*Select) iTableStatement() {}
779+
func (*ValuesStatement) iSelectStatement() {}
780+
func (*Union) iSelectStatement() {}
781+
func (*Union) iTableStatement() {}
782+
func (*Load) iStatement() {}
783+
func (*CreateDatabase) iStatement() {}
784+
func (*AlterDatabase) iStatement() {}
785+
func (*CreateTable) iStatement() {}
786+
func (*CreateView) iStatement() {}
787+
func (*AlterView) iStatement() {}
788+
func (*LockTables) iStatement() {}
789+
func (*UnlockTables) iStatement() {}
790+
func (*AlterTable) iStatement() {}
791+
func (*AlterVschema) iStatement() {}
792+
func (*AlterMigration) iStatement() {}
793+
func (*RevertMigration) iStatement() {}
794+
func (*ShowMigrationLogs) iStatement() {}
795+
func (*ShowThrottledApps) iStatement() {}
796+
func (*ShowThrottlerStatus) iStatement() {}
797+
func (*DropTable) iStatement() {}
798+
func (*DropView) iStatement() {}
799+
func (*TruncateTable) iStatement() {}
800+
func (*RenameTable) iStatement() {}
801+
func (*CallProc) iStatement() {}
802+
func (*ExplainStmt) iStatement() {}
803+
func (*VExplainStmt) iStatement() {}
804+
func (*ExplainTab) iStatement() {}
805+
func (*PrepareStmt) iStatement() {}
806+
func (*ExecuteStmt) iStatement() {}
807+
func (*DeallocateStmt) iStatement() {}
808+
func (*PurgeBinaryLogs) iStatement() {}
809+
func (*Kill) iStatement() {}
782810

783811
func (*CreateView) iDDLStatement() {}
784812
func (*AlterView) iDDLStatement() {}
@@ -1702,9 +1730,10 @@ type InsertRows interface {
17021730
SQLNode
17031731
}
17041732

1705-
func (*Select) iInsertRows() {}
1706-
func (*Union) iInsertRows() {}
1707-
func (Values) iInsertRows() {}
1733+
func (*Select) iInsertRows() {}
1734+
func (*Union) iInsertRows() {}
1735+
func (Values) iInsertRows() {}
1736+
func (*ValuesStatement) iInsertRows() {}
17081737

17091738
// OptLike works for create table xxx like xxx
17101739
type OptLike struct {
@@ -2108,13 +2137,13 @@ type (
21082137

21092138
// Subquery represents a subquery used as an value expression.
21102139
Subquery struct {
2111-
Select SelectStatement
2140+
Select TableStatement
21122141
}
21132142

21142143
// DerivedTable represents a subquery used as a table expression.
21152144
DerivedTable struct {
21162145
Lateral bool
2117-
Select SelectStatement
2146+
Select TableStatement
21182147
}
21192148
)
21202149

@@ -3575,6 +3604,18 @@ type Limit struct {
35753604
// Values represents a VALUES clause.
35763605
type Values []ValTuple
35773606

3607+
// ValuesStatement represents a VALUES statement, as in VALUES ROW(1, 2), ROW(3, 4)
3608+
type ValuesStatement struct {
3609+
With *With
3610+
// One but not both of these fields can be set.
3611+
Rows Values
3612+
ListArg ListArg
3613+
3614+
Comments *ParsedComments
3615+
Order OrderBy
3616+
Limit *Limit
3617+
}
3618+
35783619
// UpdateExprs represents a list of update expressions.
35793620
type UpdateExprs []*UpdateExpr
35803621

0 commit comments

Comments
 (0)