Skip to content

Commit

Permalink
VALUES statement AST and parsing (#17500)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
Signed-off-by: Florent Poinsard <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
Signed-off-by: Manan Gupta <[email protected]>
Co-authored-by: Andres Taylor <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
Co-authored-by: Florent Poinsard <[email protected]>
  • Loading branch information
4 people authored Jan 15, 2025
1 parent fd0ffeb commit 9d8f3d5
Show file tree
Hide file tree
Showing 57 changed files with 11,364 additions and 10,723 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/queries/random/query_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type (

// queryGenerator generates queries, which can either be unions or select statements
queryGenerator struct {
stmt sqlparser.SelectStatement
stmt sqlparser.TableStatement
selGen *selectGenerator
}

Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/vtgate/queries/random/simplifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func simplifyResultsMismatchedQuery(t *testing.T, query string) string {
require.NoError(t, err)

simplified := simplifier.SimplifyStatement(
stmt.(sqlparser.SelectStatement),
stmt.(sqlparser.TableStatement),
vSchemaWrapper.CurrentDb(),
vSchemaWrapper,
func(statement sqlparser.SelectStatement) bool {
func(statement sqlparser.TableStatement) bool {
q := sqlparser.String(statement)
_, newErr := mcmp.ExecAllowAndCompareError(q, utils.CompareOptions{})
if newErr == nil {
Expand Down
2 changes: 1 addition & 1 deletion go/test/vschemawrapper/vschema_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (vw *VSchemaWrapper) FindTable(tab sqlparser.TableName) (*vindexes.Table, s
return table, destKeyspace, destTabletType, destTarget, nil
}

func (vw *VSchemaWrapper) FindView(tab sqlparser.TableName) sqlparser.SelectStatement {
func (vw *VSchemaWrapper) FindView(tab sqlparser.TableName) sqlparser.TableStatement {
destKeyspace, _, _, err := topoproto.ParseDestination(tab.Qualifier.String(), topodatapb.TabletType_PRIMARY)
if err != nil {
return nil
Expand Down
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.

2 changes: 1 addition & 1 deletion go/vt/schemadiff/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,6 @@ func (c *CreateViewEntity) identicalOtherThanName(other *CreateViewEntity) bool
c.IsReplace == other.IsReplace &&
sqlparser.Equals.RefOfDefiner(c.Definer, other.Definer) &&
sqlparser.Equals.Columns(c.Columns, other.Columns) &&
sqlparser.Equals.SelectStatement(c.Select, other.Select) &&
sqlparser.Equals.Statement(c.Select, other.Select) &&
sqlparser.Equals.RefOfParsedComments(c.Comments, other.Comments)
}
183 changes: 112 additions & 71 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,49 @@ type (
OrderAndLimit interface {
AddOrder(*Order)
SetLimit(*Limit)
GetOrderBy() OrderBy
SetOrderBy(OrderBy)
GetLimit() *Limit
}

TableStatement interface {
iTableStatement()

InsertRows
Statement
OrderAndLimit
Commented
ColumnResults
Withable
}

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

Withable interface {
SetWith(with *With)
}

Distinctable interface {
MakeDistinct()
IsDistinct() bool
}

// SelectStatement any SELECT statement.
SelectStatement interface {
Statement
InsertRows
OrderAndLimit
Commented
ColumnResults
Withable
Distinctable
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 +184,7 @@ type (
CommonTableExpr struct {
ID IdentifierCS
Columns Columns
Subquery SelectStatement
Subquery TableStatement
}
// 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 +326,8 @@ type (
// Union represents a UNION statement.
Union struct {
With *With
Left SelectStatement
Right SelectStatement
Left TableStatement
Right TableStatement
Distinct bool
OrderBy OrderBy
Limit *Limit
Expand Down Expand Up @@ -543,7 +566,7 @@ type (
Definer *Definer
Security string
Columns Columns
Select SelectStatement
Select TableStatement
CheckOption string
IsReplace bool
Comments *ParsedComments
Expand All @@ -556,7 +579,7 @@ type (
Definer *Definer
Security string
Columns Columns
Select SelectStatement
Select TableStatement
CheckOption string
Comments *ParsedComments
}
Expand Down Expand Up @@ -727,58 +750,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) iTableStatement() {}
func (*ValuesStatement) iSelectStatement() {}
func (*Union) iSelectStatement() {}
func (*Union) iTableStatement() {}
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 +1730,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 +2137,13 @@ type (

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

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

Expand Down Expand Up @@ -3575,6 +3604,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

0 comments on commit 9d8f3d5

Please sign in to comment.