Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VALUES statement AST and parsing #17500

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions go/vt/proto/query/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

175 changes: 106 additions & 69 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,45 @@ type (
OrderAndLimit interface {
AddOrder(*Order)
SetLimit(*Limit)
GetOrderBy() OrderBy
SetOrderBy(OrderBy)
GetLimit() *Limit
}

TableSubquery interface {
iTableSubquery()

InsertRows
Statement
OrderAndLimit
Commented
ColumnResults
Withable
}

ColumnResults interface {
GetColumnCount() int
GetColumns() SelectExprs
}

Withable interface {
SetWith(with *With)
}

// SelectStatement any SELECT statement.
SelectStatement interface {
Statement
InsertRows
OrderAndLimit
Commented
ColumnResults
Withable
iSelectStatement()
GetLock() Lock
SetLock(lock Lock)
SetInto(into *SelectInto)
SetWith(with *With)
MakeDistinct()
GetColumnCount() int
GetColumns() SelectExprs
Commented
IsDistinct() bool
GetOrderBy() OrderBy
SetOrderBy(OrderBy)
GetLimit() *Limit
}

// DDLStatement represents any DDL Statement
Expand Down Expand Up @@ -161,7 +180,7 @@ type (
CommonTableExpr struct {
ID IdentifierCS
Columns Columns
Subquery SelectStatement
Subquery TableSubquery
}
// ChangeColumn is used to change the column definition, can also rename the column in alter table command
ChangeColumn struct {
Expand Down Expand Up @@ -303,8 +322,8 @@ type (
// Union represents a UNION statement.
Union struct {
With *With
Left SelectStatement
Right SelectStatement
Left TableSubquery
Right TableSubquery
Distinct bool
OrderBy OrderBy
Limit *Limit
Expand Down Expand Up @@ -543,7 +562,7 @@ type (
Definer *Definer
Security string
Columns Columns
Select SelectStatement
Select TableSubquery
CheckOption string
IsReplace bool
Comments *ParsedComments
Expand All @@ -556,7 +575,7 @@ type (
Definer *Definer
Security string
Columns Columns
Select SelectStatement
Select TableSubquery
CheckOption string
Comments *ParsedComments
}
Expand Down Expand Up @@ -727,58 +746,63 @@ type (
var _ OrderAndLimit = (*Select)(nil)
var _ OrderAndLimit = (*Update)(nil)
var _ OrderAndLimit = (*Delete)(nil)

func (*Union) iStatement() {}
func (*Select) iStatement() {}
func (*Stream) iStatement() {}
func (*VStream) iStatement() {}
func (*Insert) iStatement() {}
func (*Update) iStatement() {}
func (*Delete) iStatement() {}
func (*Set) iStatement() {}
func (*DropDatabase) iStatement() {}
func (*Flush) iStatement() {}
func (*Show) iStatement() {}
func (*Use) iStatement() {}
func (*Begin) iStatement() {}
func (*Commit) iStatement() {}
func (*Rollback) iStatement() {}
func (*SRollback) iStatement() {}
func (*Savepoint) iStatement() {}
func (*Release) iStatement() {}
func (*Analyze) iStatement() {}
func (*OtherAdmin) iStatement() {}
func (*CommentOnly) iStatement() {}
func (*Select) iSelectStatement() {}
func (*Union) iSelectStatement() {}
func (*Load) iStatement() {}
func (*CreateDatabase) iStatement() {}
func (*AlterDatabase) iStatement() {}
func (*CreateTable) iStatement() {}
func (*CreateView) iStatement() {}
func (*AlterView) iStatement() {}
func (*LockTables) iStatement() {}
func (*UnlockTables) iStatement() {}
func (*AlterTable) iStatement() {}
func (*AlterVschema) iStatement() {}
func (*AlterMigration) iStatement() {}
func (*RevertMigration) iStatement() {}
func (*ShowMigrationLogs) iStatement() {}
func (*ShowThrottledApps) iStatement() {}
func (*ShowThrottlerStatus) iStatement() {}
func (*DropTable) iStatement() {}
func (*DropView) iStatement() {}
func (*TruncateTable) iStatement() {}
func (*RenameTable) iStatement() {}
func (*CallProc) iStatement() {}
func (*ExplainStmt) iStatement() {}
func (*VExplainStmt) iStatement() {}
func (*ExplainTab) iStatement() {}
func (*PrepareStmt) iStatement() {}
func (*ExecuteStmt) iStatement() {}
func (*DeallocateStmt) iStatement() {}
func (*PurgeBinaryLogs) iStatement() {}
func (*Kill) iStatement() {}
var _ OrderAndLimit = (*ValuesStatement)(nil)

func (*Union) iStatement() {}
func (*Select) iStatement() {}
func (*ValuesStatement) iStatement() {}
func (*Stream) iStatement() {}
func (*VStream) iStatement() {}
func (*Insert) iStatement() {}
func (*Update) iStatement() {}
func (*Delete) iStatement() {}
func (*Set) iStatement() {}
func (*DropDatabase) iStatement() {}
func (*Flush) iStatement() {}
func (*Show) iStatement() {}
func (*Use) iStatement() {}
func (*Begin) iStatement() {}
func (*Commit) iStatement() {}
func (*Rollback) iStatement() {}
func (*SRollback) iStatement() {}
func (*Savepoint) iStatement() {}
func (*Release) iStatement() {}
func (*Analyze) iStatement() {}
func (*OtherAdmin) iStatement() {}
func (*CommentOnly) iStatement() {}
func (*Select) iSelectStatement() {}
func (*Select) iTableSubquery() {}
func (*ValuesStatement) iSelectStatement() {}
func (*Union) iSelectStatement() {}
func (*Union) iTableSubquery() {}
func (*Load) iStatement() {}
func (*CreateDatabase) iStatement() {}
func (*AlterDatabase) iStatement() {}
func (*CreateTable) iStatement() {}
func (*CreateView) iStatement() {}
func (*AlterView) iStatement() {}
func (*LockTables) iStatement() {}
func (*UnlockTables) iStatement() {}
func (*AlterTable) iStatement() {}
func (*AlterVschema) iStatement() {}
func (*AlterMigration) iStatement() {}
func (*RevertMigration) iStatement() {}
func (*ShowMigrationLogs) iStatement() {}
func (*ShowThrottledApps) iStatement() {}
func (*ShowThrottlerStatus) iStatement() {}
func (*DropTable) iStatement() {}
func (*DropView) iStatement() {}
func (*TruncateTable) iStatement() {}
func (*RenameTable) iStatement() {}
func (*CallProc) iStatement() {}
func (*ExplainStmt) iStatement() {}
func (*VExplainStmt) iStatement() {}
func (*ExplainTab) iStatement() {}
func (*PrepareStmt) iStatement() {}
func (*ExecuteStmt) iStatement() {}
func (*DeallocateStmt) iStatement() {}
func (*PurgeBinaryLogs) iStatement() {}
func (*Kill) iStatement() {}

func (*CreateView) iDDLStatement() {}
func (*AlterView) iDDLStatement() {}
Expand Down Expand Up @@ -1702,9 +1726,10 @@ type InsertRows interface {
SQLNode
}

func (*Select) iInsertRows() {}
func (*Union) iInsertRows() {}
func (Values) iInsertRows() {}
func (*Select) iInsertRows() {}
func (*Union) iInsertRows() {}
func (Values) iInsertRows() {}
func (*ValuesStatement) iInsertRows() {}

// OptLike works for create table xxx like xxx
type OptLike struct {
Expand Down Expand Up @@ -2108,13 +2133,13 @@ type (

// Subquery represents a subquery used as an value expression.
Subquery struct {
Select SelectStatement
Select TableSubquery
}

// DerivedTable represents a subquery used as a table expression.
DerivedTable struct {
Lateral bool
Select SelectStatement
Select TableSubquery
}
)

Expand Down Expand Up @@ -3575,6 +3600,18 @@ type Limit struct {
// Values represents a VALUES clause.
type Values []ValTuple

// ValuesStatement represents a VALUES statement, as in VALUES ROW(1, 2), ROW(3, 4)
type ValuesStatement struct {
With *With
// One but not both of these fields can be set.
Rows Values
ListArg ListArg

Comments *ParsedComments
Order OrderBy
Limit *Limit
}

// UpdateExprs represents a list of update expressions.
type UpdateExprs []*UpdateExpr

Expand Down
Loading
Loading