Repository: vitessio/vitess
Pull request #7096 (2020-12-02 07:22:17)

Convert usages of DDL struct to DDLStatement interface
All the occurences of DDL struct have been converted to DDLStatement interface. This is done so that further addition of newer constructs to DDLStatement interface does not affect the current functionality. The end goal is to remove the various functions added to the interface in this PR and convert them to a type switch for specific constructs.


Patch:
diff --git a/go/vt/schemamanager/tablet_executor.go b/go/vt/schemamanager/tablet_executor.go
index e463461cbd..6c7094c5c9 100644
--- a/go/vt/schemamanager/tablet_executor.go
+++ b/go/vt/schemamanager/tablet_executor.go
@@ -128,8 +128,8 @@ func (exec *TabletExecutor) Validate(ctx context.Context, sqls []string) error {
 	return err
 }
 
-func (exec *TabletExecutor) parseDDLs(sqls []string) ([]*sqlparser.DDL, []sqlparser.DBDDLStatement, error) {
-	parsedDDLs := make([]*sqlparser.DDL, 0)
+func (exec *TabletExecutor) parseDDLs(sqls []string) ([]sqlparser.DDLStatement, []sqlparser.DBDDLStatement, error) {
+	parsedDDLs := make([]sqlparser.DDLStatement, 0)
 	parsedDBDDLs := make([]sqlparser.DBDDLStatement, 0)
 	for _, sql := range sqls {
 		stat, err := sqlparser.Parse(sql)
@@ -137,7 +137,7 @@ func (exec *TabletExecutor) parseDDLs(sqls []string) ([]*sqlparser.DDL, []sqlpar
 			return nil, nil, fmt.Errorf("failed to parse sql: %s, got error: %v", sql, err)
 		}
 		switch ddl := stat.(type) {
-		case *sqlparser.DDL:
+		case sqlparser.DDLStatement:
 			parsedDDLs = append(parsedDDLs, ddl)
 		case sqlparser.DBDDLStatement:
 			parsedDBDDLs = append(parsedDBDDLs, ddl)
@@ -151,11 +151,11 @@ func (exec *TabletExecutor) parseDDLs(sqls []string) ([]*sqlparser.DDL, []sqlpar
 }
 
 // IsOnlineSchemaDDL returns true if the query is an online schema change DDL
-func (exec *TabletExecutor) isOnlineSchemaDDL(ddl *sqlparser.DDL) (isOnline bool, strategy schema.DDLStrategy, options string) {
+func (exec *TabletExecutor) isOnlineSchemaDDL(ddl sqlparser.DDLStatement) (isOnline bool, strategy schema.DDLStrategy, options string) {
 	if ddl == nil {
 		return false, strategy, options
 	}
-	if ddl.Action != sqlparser.AlterDDLAction {
+	if ddl.GetAction() != sqlparser.AlterDDLAction {
 		return false, strategy, options
 	}
 	strategy, options, _ = schema.ParseDDLStrategy(exec.ddlStrategy)
@@ -169,7 +169,7 @@ func (exec *TabletExecutor) isOnlineSchemaDDL(ddl *sqlparser.DDL) (isOnline bool
 // to be a big schema change and will be rejected.
 //   1. Alter more than 100,000 rows.
 //   2. Change a table with more than 2,000,000 rows (Drops are fine).
-func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDDLs []*sqlparser.DDL) (bool, error) {
+func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDDLs []sqlparser.DDLStatement) (bool, error) {
 	// exec.tablets is guaranteed to have at least one element;
 	// Otherwise, Open should fail and executor should fail.
 	masterTabletInfo := exec.tablets[0]
@@ -188,13 +188,13 @@ func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDD
 			// Since this is an online schema change, there is no need to worry about big changes
 			continue
 		}
-		switch ddl.Action {
+		switch ddl.GetAction() {
 		case sqlparser.DropDDLAction, sqlparser.CreateDDLAction, sqlparser.TruncateDDLAction, sqlparser.RenameDDLAction:
 			continue
 		}
-		tableName := ddl.Table.Name.String()
+		tableName := ddl.GetTable().Name.String()
 		if rowCount, ok := tableWithCount[tableName]; ok {
-			if rowCount > 100000 && ddl.Action == sqlparser.AlterDDLAction {
+			if rowCount > 100000 && ddl.GetAction() == sqlparser.AlterDDLAction {
 				return true, fmt.Errorf(
 					"big schema change detected. Disable check with -allow_long_unavailability. ddl: %s alters a table with more than 100 thousand rows", sqlparser.String(ddl))
 			}
@@ -257,8 +257,8 @@ func (exec *TabletExecutor) Execute(ctx context.Context, sqls []string) *Execute
 		isOnlineDDL, strategy, options := exec.isOnlineSchemaDDL(nil)
 		tableName := ""
 		switch ddl := stat.(type) {
-		case *sqlparser.DDL:
-			tableName = ddl.Table.Name.String()
+		case sqlparser.DDLStatement:
+			tableName = ddl.GetTable().Name.String()
 			isOnlineDDL, strategy, options = exec.isOnlineSchemaDDL(ddl)
 		}
 		exec.wr.Logger().Infof("Received DDL request. strategy=%+v", strategy)
diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go
index df84a7b5fd..2478d5daff 100644
--- a/go/vt/sqlparser/ast.go
+++ b/go/vt/sqlparser/ast.go
@@ -61,6 +61,13 @@ type (
 		IsFullyParsed() bool
 		GetTable() TableName
 		GetAction() DDLAction
+		GetOptLike() *OptLike
+		GetTableSpec() *TableSpec
+		GetVindexSpec() *VindexSpec
+		GetFromTables() TableNames
+		GetToTables() TableNames
+		GetAutoIncSpec() *AutoIncSpec
+		GetVindexCols() []ColIdent
 		AffectedTables() TableNames
 		SetTable(qualifier string, name string)
 		Statement
@@ -413,6 +420,76 @@ func (node *CreateIndex) GetAction() DDLAction {
 	return AlterDDLAction
 }
 
+// GetOptLike implements the DDLStatement interface
+func (node *DDL) GetOptLike() *OptLike {
+	return node.OptLike
+}
+
+// GetOptLike implements the DDLStatement interface
+func (node *CreateIndex) GetOptLike() *OptLike {
+	return nil
+}
+
+// GetTableSpec implements the DDLStatement interface
+func (node *DDL) GetTableSpec() *TableSpec {
+	return node.TableSpec
+}
+
+// GetTableSpec implements the DDLStatement interface
+func (node *CreateIndex) GetTableSpec() *TableSpec {
+	return nil
+}
+
+// GetVindexSpec implements the DDLStatement interface
+func (node *DDL) GetVindexSpec() *VindexSpec {
+	return node.VindexSpec
+}
+
+// GetVindexSpec implements the DDLStatement interface
+func (node *CreateIndex) GetVindexSpec() *VindexSpec {
+	return nil
+}
+
+// GetFromTables implements the DDLStatement interface
+func (node *DDL) GetFromTables() TableNames {
+	return node.FromTables
+}
+
+// GetFromTables implements the DDLStatement interface
+func (node *CreateIndex) GetFromTables() TableNames {
+	return nil
+}
+
+// GetToTables implements the DDLStatement interface
+func (node *DDL) GetToTables() TableNames {
+	return node.ToTables
+}
+
+// GetToTables implements the DDLStatement interface
+func (node *CreateIndex) GetToTables() TableNames {
+	return nil
+}
+
+// GetAutoIncSpec implements the DDLStatement interface
+func (node *DDL) GetAutoIncSpec() *AutoIncSpec {
+	return node.AutoIncSpec
+}
+
+// GetAutoIncSpec implements the DDLStatement interface
+func (node *CreateIndex) GetAutoIncSpec() *AutoIncSpec {
+	return nil
+}
+
+// GetVindexCols implements the DDLStatement interface
+func (node *DDL) GetVindexCols() []ColIdent {
+	return node.VindexCols
+}
+
+// GetVindexCols implements the DDLStatement interface
+func (node *CreateIndex) GetVindexCols() []ColIdent {
+	return nil
+}
+
 // GetAction implements the DDLStatement interface
 func (node *DDL) GetAction() DDLAction {
 	return node.Action
diff --git a/go/vt/sqlparser/normalizer.go b/go/vt/sqlparser/normalizer.go
index 64f50dca13..ea5f7c3ee0 100644
--- a/go/vt/sqlparser/normalizer.go
+++ b/go/vt/sqlparser/normalizer.go
@@ -60,7 +60,7 @@ func newNormalizer(stmt Statement, bindVars map[string]*querypb.BindVariable, pr
 func (nz *normalizer) WalkStatement(cursor *Cursor) bool {
 	switch node := cursor.Node().(type) {
 	// no need to normalize the statement types
-	case *Set, *Show, *Begin, *Commit, *Rollback, *Savepoint, *SetTransaction, *DDL, *SRollback, *Release, *OtherAdmin, *OtherRead:
+	case *Set, *Show, *Begin, *Commit, *Rollback, *Savepoint, *SetTransaction, DDLStatement, *SRollback, *Release, *OtherAdmin, *OtherRead:
 		return false
 	case *Select:
 		Rewrite(node, nz.WalkSelect, nil)
diff --git a/go/vt/topotools/vschema_ddl.go b/go/vt/topotools/vschema_ddl.go
index a268888c6c..c6745b0124 100644
--- a/go/vt/topotools/vschema_ddl.go
+++ b/go/vt/topotools/vschema_ddl.go
@@ -29,7 +29,7 @@ import (
 
 // ApplyVSchemaDDL applies the given DDL statement to the vschema
 // keyspace definition and returns the modified keyspace object.
-func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL) (*vschemapb.Keyspace, error) {
+func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl sqlparser.DDLStatement) (*vschemapb.Keyspace, error) {
 	if ks == nil {
 		ks = new(vschemapb.Keyspace)
 	}
@@ -44,14 +44,14 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 
 	var tableName string
 	var table *vschemapb.Table
-	if !ddl.Table.IsEmpty() {
-		tableName = ddl.Table.Name.String()
+	if !ddl.GetTable().IsEmpty() {
+		tableName = ddl.GetTable().Name.String()
 		table = ks.Tables[tableName]
 	}
 
-	switch ddl.Action {
+	switch ddl.GetAction() {
 	case sqlparser.CreateVindexDDLAction:
-		name := ddl.VindexSpec.Name.String()
+		name := ddl.GetVindexSpec().Name.String()
 		if _, ok := ks.Vindexes[name]; ok {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vindex %s already exists in keyspace %s", name, ksName)
 		}
@@ -62,9 +62,9 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 			ks.Sharded = true
 		}
 
-		owner, params := ddl.VindexSpec.ParseParams()
+		owner, params := ddl.GetVindexSpec().ParseParams()
 		ks.Vindexes[name] = &vschemapb.Vindex{
-			Type:   ddl.VindexSpec.Type.String(),
+			Type:   ddl.GetVindexSpec().Type.String(),
 			Params: params,
 			Owner:  owner,
 		}
@@ -72,7 +72,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 		return ks, nil
 
 	case sqlparser.DropVindexDDLAction:
-		name := ddl.VindexSpec.Name.String()
+		name := ddl.GetVindexSpec().Name.String()
 		if _, ok := ks.Vindexes[name]; !ok {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vindex %s does not exists in keyspace %s", name, ksName)
 		}
@@ -95,7 +95,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "add vschema table: unsupported on sharded keyspace %s", ksName)
 		}
 
-		name := ddl.Table.Name.String()
+		name := ddl.GetTable().Name.String()
 		if _, ok := ks.Tables[name]; ok {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema already contains table %s in keyspace %s", name, ksName)
 		}
@@ -105,7 +105,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 		return ks, nil
 
 	case sqlparser.DropVschemaTableDDLAction:
-		name := ddl.Table.Name.String()
+		name := ddl.GetTable().Name.String()
 		if _, ok := ks.Tables[name]; !ok {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema does not contain table %s in keyspace %s", name, ksName)
 		}
@@ -123,7 +123,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 		//
 		// 2. The vindex type is not specified. Make sure the vindex
 		//    already exists.
-		spec := ddl.VindexSpec
+		spec := ddl.GetVindexSpec()
 		name := spec.Name.String()
 		if !spec.Type.IsEmpty() {
 			owner, params := spec.ParseParams()
@@ -171,8 +171,8 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 			}
 		}
 
-		columns := make([]string, len(ddl.VindexCols))
-		for i, col := range ddl.VindexCols {
+		columns := make([]string, len(ddl.GetVindexCols()))
+		for i, col := range ddl.GetVindexCols() {
 			columns[i] = col.String()
 		}
 		table.ColumnVindexes = append(table.ColumnVindexes, &vschemapb.ColumnVindex{
@@ -184,7 +184,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 		return ks, nil
 
 	case sqlparser.DropColVindexDDLAction:
-		spec := ddl.VindexSpec
+		spec := ddl.GetVindexSpec()
 		name := spec.Name.String()
 		if table == nil {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "table %s.%s not defined in vschema", ksName, tableName)
@@ -206,7 +206,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "add sequence table: unsupported on sharded keyspace %s", ksName)
 		}
 
-		name := ddl.Table.Name.String()
+		name := ddl.GetTable().Name.String()
 		if _, ok := ks.Tables[name]; ok {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema already contains sequence %s in keyspace %s", name, ksName)
 		}
@@ -216,7 +216,7 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 		return ks, nil
 
 	case sqlparser.AddAutoIncDDLAction:
-		name := ddl.Table.Name.String()
+		name := ddl.GetTable().Name.String()
 		table := ks.Tables[name]
 		if table == nil {
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema does not contain table %s in keyspace %s", name, ksName)
@@ -226,19 +226,19 @@ func ApplyVSchemaDDL(ksName string, ks *vschemapb.Keyspace, ddl *sqlparser.DDL)
 			return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema already contains auto inc %v on table %s in keyspace %s", table.AutoIncrement, name, ksName)
 		}
 
-		sequence := ddl.AutoIncSpec.Sequence
+		sequence := ddl.GetAutoIncSpec().Sequence
 		sequenceFqn := sequence.Name.String()
 		if sequence.Qualifier.String() != "" {
 			sequenceFqn = fmt.Sprintf("%s.%s", sequence.Qualifier.String(), sequenceFqn)
 		}
 
 		table.AutoIncrement = &vschemapb.AutoIncrement{
-			Column:   ddl.AutoIncSpec.Column.String(),
+			Column:   ddl.GetAutoIncSpec().Column.String(),
 			Sequence: sequenceFqn,
 		}
 
 		return ks, nil
 	}
 
-	return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected vindex ddl operation %s", ddl.Action.ToString())
+	return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "unexpected vindex ddl operation %s", ddl.GetAction().ToString())
 }
diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go
index e6f1db2fad..33b66033b6 100644
--- a/go/vt/vtctl/vtctl.go
+++ b/go/vt/vtctl/vtctl.go
@@ -2767,7 +2767,7 @@ func commandApplyVSchema(ctx context.Context, wr *wrangler.Wrangler, subFlags *f
 		if err != nil {
 			return fmt.Errorf("error parsing vschema statement `%s`: %v", *sql, err)
 		}
-		ddl, ok := stmt.(*sqlparser.DDL)
+		ddl, ok := stmt.(sqlparser.DDLStatement)
 		if !ok {
 			return fmt.Errorf("error parsing vschema statement `%s`: not a ddl statement", *sql)
 		}
diff --git a/go/vt/vtexplain/vtexplain.go b/go/vt/vtexplain/vtexplain.go
index 63a384c79c..6c4476ebbf 100644
--- a/go/vt/vtexplain/vtexplain.go
+++ b/go/vt/vtexplain/vtexplain.go
@@ -181,8 +181,8 @@ func Stop() {
 	}
 }
 
-func parseSchema(sqlSchema string, opts *Options) ([]*sqlparser.DDL, error) {
-	parsedDDLs := make([]*sqlparser.DDL, 0, 16)
+func parseSchema(sqlSchema string, opts *Options) ([]sqlparser.DDLStatement, error) {
+	parsedDDLs := make([]sqlparser.DDLStatement, 0, 16)
 	for {
 		sql, rem, err := sqlparser.SplitStatement(sqlSchema)
 		sqlSchema = rem
@@ -210,16 +210,16 @@ func parseSchema(sqlSchema string, opts *Options) ([]*sqlparser.DDL, error) {
 				continue
 			}
 		}
-		ddl, ok := stmt.(*sqlparser.DDL)
+		ddl, ok := stmt.(sqlparser.DDLStatement)
 		if !ok {
 			log.Infof("ignoring non-DDL statement: %s", sql)
 			continue
 		}
-		if ddl.Action != sqlparser.CreateDDLAction {
-			log.Infof("ignoring %s table statement", ddl.Action.ToString())
+		if ddl.GetAction() != sqlparser.CreateDDLAction {
+			log.Infof("ignoring %s table statement", ddl.GetAction().ToString())
 			continue
 		}
-		if ddl.TableSpec == nil && ddl.OptLike == nil {
+		if ddl.GetTableSpec() == nil && ddl.GetOptLike() == nil {
 			log.Errorf("invalid create table statement: %s", sql)
 			continue
 		}
diff --git a/go/vt/vtexplain/vtexplain_vttablet.go b/go/vt/vtexplain/vtexplain_vttablet.go
index 6cd44416bb..193da213c1 100644
--- a/go/vt/vtexplain/vtexplain_vttablet.go
+++ b/go/vt/vtexplain/vtexplain_vttablet.go
@@ -270,7 +270,7 @@ func (t *explainTablet) Close(ctx context.Context) error {
 	return t.tsv.Close(ctx)
 }
 
-func initTabletEnvironment(ddls []*sqlparser.DDL, opts *Options) error {
+func initTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) error {
 	tableColumns = make(map[string]map[string]querypb.Type)
 	schemaQueries = map[string]*sqltypes.Result{
 		"select unix_timestamp()": {
@@ -370,7 +370,7 @@ func initTabletEnvironment(ddls []*sqlparser.DDL, opts *Options) error {
 
 	showTableRows := make([][]sqltypes.Value, 0, 4)
 	for _, ddl := range ddls {
-		table := ddl.Table.Name.String()
+		table := ddl.GetTable().Name.String()
 		showTableRows = append(showTableRows, mysql.BaseShowTablesRow(table, false, ""))
 	}
 	schemaQueries[mysql.BaseShowTables] = &sqltypes.Result{
@@ -380,17 +380,17 @@ func initTabletEnvironment(ddls []*sqlparser.DDL, opts *Options) error {
 
 	indexRows := make([][]sqltypes.Value, 0, 4)
 	for _, ddl := range ddls {
-		table := sqlparser.String(ddl.Table.Name)
+		table := sqlparser.String(ddl.GetTable().Name)
 
-		if ddl.OptLike != nil {
-			likeTable := ddl.OptLike.LikeTable.Name.String()
+		if ddl.GetOptLike() != nil {
+			likeTable := ddl.GetOptLike().LikeTable.Name.String()
 			if _, ok := schemaQueries["select * from "+likeTable+" where 1 != 1"]; !ok {
 				return fmt.Errorf("check your schema, table[%s] doesn't exist", likeTable)
 			}
 			schemaQueries["select * from "+table+" where 1 != 1"] = schemaQueries["select * from "+likeTable+" where 1 != 1"]
 			continue
 		}
-		for _, idx := range ddl.TableSpec.Indexes {
+		for _, idx := range ddl.GetTableSpec().Indexes {
 			if !idx.Info.Primary {
 				continue
 			}
@@ -402,7 +402,7 @@ func initTabletEnvironment(ddls []*sqlparser.DDL, opts *Options) error {
 
 		tableColumns[table] = make(map[string]querypb.Type)
 		var rowTypes []*querypb.Field
-		for _, col := range ddl.TableSpec.Columns {
+		for _, col := range ddl.GetTableSpec().Columns {
 			colName := strings.ToLower(col.Name.String())
 			rowType := &querypb.Field{
 				Name: colName,
diff --git a/go/vt/vtgate/engine/primitive.go b/go/vt/vtgate/engine/primitive.go
index 93875593c1..587aa9bc43 100644
--- a/go/vt/vtgate/engine/primitive.go
+++ b/go/vt/vtgate/engine/primitive.go
@@ -84,7 +84,7 @@ type (
 		// Will replace all of the Topo functions.
 		ResolveDestinations(keyspace string, ids []*querypb.Value, destinations []key.Destination) ([]*srvtopo.ResolvedShard, [][]*querypb.Value, error)
 
-		ExecuteVSchema(keyspace string, vschemaDDL *sqlparser.DDL) error
+		ExecuteVSchema(keyspace string, vschemaDDL sqlparser.DDLStatement) error
 
 		SubmitOnlineDDL(onlineDDl *schema.OnlineDDL) error
 
diff --git a/go/vt/vtgate/engine/vschema_ddl.go b/go/vt/vtgate/engine/vschema_ddl.go
index 29085a6603..3fe128ff32 100644
--- a/go/vt/vtgate/engine/vschema_ddl.go
+++ b/go/vt/vtgate/engine/vschema_ddl.go
@@ -31,7 +31,7 @@ var _ Primitive = (*AlterVSchema)(nil)
 type AlterVSchema struct {
 	Keyspace *vindexes.Keyspace
 
-	DDL *sqlparser.DDL
+	DDL sqlparser.DDLStatement
 
 	noTxNeeded
 
@@ -60,7 +60,7 @@ func (v *AlterVSchema) GetKeyspaceName() string {
 
 //GetTableName implements the Primitive interface
 func (v *AlterVSchema) GetTableName() string {
-	return v.DDL.Table.Name.String()
+	return v.DDL.GetTable().Name.String()
 }
 
 //Execute implements the Primitive interface
diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go
index 091d9ca5a2..4237c83125 100644
--- a/go/vt/vtgate/vcursor_impl.go
+++ b/go/vt/vtgate/vcursor_impl.go
@@ -103,7 +103,7 @@ func (vc *vcursorImpl) GetKeyspace() string {
 	return vc.keyspace
 }
 
-func (vc *vcursorImpl) ExecuteVSchema(keyspace string, vschemaDDL *sqlparser.DDL) error {
+func (vc *vcursorImpl) ExecuteVSchema(keyspace string, vschemaDDL sqlparser.DDLStatement) error {
 	srvVschema := vc.vm.GetCurrentSrvVschema()
 	if srvVschema == nil {
 		return vterrors.Errorf(vtrpcpb.Code_INTERNAL, "vschema not loaded")
@@ -117,8 +117,8 @@ func (vc *vcursorImpl) ExecuteVSchema(keyspace string, vschemaDDL *sqlparser.DDL
 
 	// Resolve the keyspace either from the table qualifier or the target keyspace
 	var ksName string
-	if !vschemaDDL.Table.IsEmpty() {
-		ksName = vschemaDDL.Table.Qualifier.String()
+	if !vschemaDDL.GetTable().IsEmpty() {
+		ksName = vschemaDDL.GetTable().Qualifier.String()
 	}
 	if ksName == "" {
 		ksName = keyspace
diff --git a/go/vt/vttablet/tabletserver/vstreamer/planbuilder.go b/go/vt/vttablet/tabletserver/vstreamer/planbuilder.go
index 54c7021bd8..3454183b06 100644
--- a/go/vt/vttablet/tabletserver/vstreamer/planbuilder.go
+++ b/go/vt/vttablet/tabletserver/vstreamer/planbuilder.go
@@ -197,16 +197,12 @@ func mustSendDDL(query mysql.Query, dbname string, filter *binlogdatapb.Filter)
 		if !stmt.GetTable().IsEmpty() {
 			return tableMatches(stmt.GetTable(), dbname, filter)
 		}
-		ddlStmt, isDDL := stmt.(*sqlparser.DDL)
-		if !isDDL {
-			return false
-		}
-		for _, table := range ddlStmt.FromTables {
+		for _, table := range stmt.GetFromTables() {
 			if tableMatches(table, dbname, filter) {
 				return true
 			}
 		}
-		for _, table := range ddlStmt.ToTables {
+		for _, table := range stmt.GetToTables() {
 			if tableMatches(table, dbname, filter) {
 				return true
 			}
diff --git a/go/vt/wrangler/materializer.go b/go/vt/wrangler/materializer.go
index cdbb75d3b5..cce22b66fe 100644
--- a/go/vt/wrangler/materializer.go
+++ b/go/vt/wrangler/materializer.go
@@ -950,9 +950,9 @@ func stripTableConstraints(ddl string) (string, error) {
 
 	stripConstraints := func(cursor *sqlparser.Cursor) bool {
 		switch node := cursor.Node().(type) {
-		case *sqlparser.DDL:
-			if node.TableSpec != nil {
-				node.TableSpec.Constraints = nil
+		case sqlparser.DDLStatement:
+			if node.GetTableSpec() != nil {
+				node.GetTableSpec().Constraints = nil
 			}
 		}
 		return true


Test patch:
diff --git a/go/vt/schemamanager/tablet_executor_test.go b/go/vt/schemamanager/tablet_executor_test.go
index 265077d5db..f8e5fb4b35 100644
--- a/go/vt/schemamanager/tablet_executor_test.go
+++ b/go/vt/schemamanager/tablet_executor_test.go
@@ -266,7 +266,7 @@ func TestIsOnlineSchemaDDL(t *testing.T) {
 		stmt, err := sqlparser.Parse(ts.query)
 		assert.NoError(t, err)
 
-		ddl, ok := stmt.(*sqlparser.DDL)
+		ddl, ok := stmt.(sqlparser.DDLStatement)
 		assert.True(t, ok)
 
 		isOnlineDDL, strategy, options := e.isOnlineSchemaDDL(ddl)
diff --git a/go/vt/sqlparser/ast_test.go b/go/vt/sqlparser/ast_test.go
index d2de431d06..405df6c5b5 100644
--- a/go/vt/sqlparser/ast_test.go
+++ b/go/vt/sqlparser/ast_test.go
@@ -177,7 +177,7 @@ func TestSetLimit(t *testing.T) {
 func TestDDL(t *testing.T) {
 	testcases := []struct {
 		query    string
-		output   *DDL
+		output   DDLStatement
 		affected []string
 	}{{
 		query: "create table a",
@@ -244,7 +244,7 @@ func TestDDL(t *testing.T) {
 		for _, t := range tcase.affected {
 			want = append(want, TableName{Name: NewTableIdent(t)})
 		}
-		if affected := got.(*DDL).AffectedTables(); !reflect.DeepEqual(affected, want) {
+		if affected := got.(DDLStatement).AffectedTables(); !reflect.DeepEqual(affected, want) {
 			t.Errorf("Affected(%s): %v, want %v", tcase.query, affected, want)
 		}
 	}
diff --git a/go/vt/vtgate/engine/fake_vcursor_test.go b/go/vt/vtgate/engine/fake_vcursor_test.go
index 91a53f8ef7..09ac0bfd2c 100644
--- a/go/vt/vtgate/engine/fake_vcursor_test.go
+++ b/go/vt/vtgate/engine/fake_vcursor_test.go
@@ -116,7 +116,7 @@ func (t noopVCursor) ShardSession() []*srvtopo.ResolvedShard {
 	panic("implement me")
 }
 
-func (t noopVCursor) ExecuteVSchema(keyspace string, vschemaDDL *sqlparser.DDL) error {
+func (t noopVCursor) ExecuteVSchema(keyspace string, vschemaDDL sqlparser.DDLStatement) error {
 	panic("implement me")
 }
 
@@ -281,7 +281,7 @@ func (f *loggingVCursor) ShardSession() []*srvtopo.ResolvedShard {
 	return nil
 }
 
-func (f *loggingVCursor) ExecuteVSchema(string, *sqlparser.DDL) error {
+func (f *loggingVCursor) ExecuteVSchema(string, sqlparser.DDLStatement) error {
 	panic("implement me")
 }