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

Adds Planning and Parsing Support for Drop View #7190

Closed
wants to merge 6 commits into from
Closed
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
13 changes: 8 additions & 5 deletions go/test/endtoend/vtgate/unsharded/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestInsertAllDefaults(t *testing.T) {
assertMatches(t, conn, `select * from allDefaults`, "[[INT64(1) NULL]]")
}

func TestCreateViewUnsharded(t *testing.T) {
func TestDDLUnsharded(t *testing.T) {
defer cluster.PanicHandler(t)
ctx := context.Background()
vtParams := mysql.ConnParams{
Expand All @@ -203,12 +203,15 @@ func TestCreateViewUnsharded(t *testing.T) {
conn, err := mysql.Connect(ctx, &vtParams)
require.NoError(t, err)
defer conn.Close()
defer exec(t, conn, `delete from t1`)

exec(t, conn, `create table tempt1(c1 BIGINT NOT NULL,c2 BIGINT NOT NULL,c3 BIGINT,c4 varchar(100),PRIMARY KEY (c1), UNIQUE KEY (c2),UNIQUE KEY (c3), UNIQUE KEY (c4))`)
// Test that create view works and the output is as expected
_, err = conn.ExecuteFetch(`create view v1 as select * from t1`, 1000, true)
require.NoError(t, err)
exec(t, conn, `insert into t1(c1, c2, c3, c4) values (300,100,300,'abc'),(30,10,30,'ac'),(3,0,3,'a')`)
exec(t, conn, `create view v1 as select * from tempt1`)
exec(t, conn, `insert into tempt1(c1, c2, c3, c4) values (300,100,300,'abc'),(30,10,30,'ac'),(3,0,3,'a')`)
assertMatches(t, conn, "select * from v1", `[[INT64(3) INT64(0) INT64(3) VARCHAR("a")] [INT64(30) INT64(10) INT64(30) VARCHAR("ac")] [INT64(300) INT64(100) INT64(300) VARCHAR("abc")]]`)
exec(t, conn, `drop view v1`)
exec(t, conn, `drop table tempt1`)
assertMatches(t, conn, "show tables", `[[VARCHAR("allDefaults")] [VARCHAR("t1")]]`)
}

func exec(t *testing.T, conn *mysql.Conn, query string) *sqltypes.Result {
Expand Down
75 changes: 75 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ type (
AutoIncSpec *AutoIncSpec
}

// DropView represents a DROP VIEW statement.
DropView struct {
FromTables TableNames
IfExists bool
}

// CreateIndex represents a CREATE INDEX query
CreateIndex struct {
Constraint string
Expand Down Expand Up @@ -438,11 +444,13 @@ func (*CreateTable) iStatement() {}
func (*CreateView) iStatement() {}
func (*LockTables) iStatement() {}
func (*UnlockTables) iStatement() {}
func (*DropView) iStatement() {}

func (*DDL) iDDLStatement() {}
func (*CreateIndex) iDDLStatement() {}
func (*CreateView) iDDLStatement() {}
func (*CreateTable) iDDLStatement() {}
func (*DropView) iDDLStatement() {}

// IsFullyParsed implements the DDLStatement interface
func (*DDL) IsFullyParsed() bool {
Expand All @@ -464,6 +472,11 @@ func (node *CreateView) IsFullyParsed() bool {
return true
}

// IsFullyParsed implements the DDLStatement interface
func (node *DropView) IsFullyParsed() bool {
return true
}

// GetTable implements the DDLStatement interface
func (node *CreateIndex) GetTable() TableName {
return node.Table
Expand All @@ -484,6 +497,11 @@ func (node *DDL) GetTable() TableName {
return node.Table
}

// GetTable implements the DDLStatement interface
func (node *DropView) GetTable() TableName {
return TableName{}
}

// GetAction implements the DDLStatement interface
func (node *DDL) GetAction() DDLAction {
return node.Action
Expand All @@ -504,6 +522,11 @@ func (node *CreateView) GetAction() DDLAction {
return CreateDDLAction
}

// GetAction implements the DDLStatement interface
func (node *DropView) GetAction() DDLAction {
return DropDDLAction
}

// GetOptLike implements the DDLStatement interface
func (node *DDL) GetOptLike() *OptLike {
return node.OptLike
Expand All @@ -524,6 +547,11 @@ func (node *CreateView) GetOptLike() *OptLike {
return nil
}

// GetOptLike implements the DDLStatement interface
func (node *DropView) GetOptLike() *OptLike {
return nil
}

// GetTableSpec implements the DDLStatement interface
func (node *DDL) GetTableSpec() *TableSpec {
return node.TableSpec
Expand All @@ -544,6 +572,11 @@ func (node *CreateView) GetTableSpec() *TableSpec {
return nil
}

// GetTableSpec implements the DDLStatement interface
func (node *DropView) GetTableSpec() *TableSpec {
return nil
}

// GetVindexSpec implements the DDLStatement interface
func (node *DDL) GetVindexSpec() *VindexSpec {
return node.VindexSpec
Expand All @@ -564,6 +597,11 @@ func (node *CreateView) GetVindexSpec() *VindexSpec {
return nil
}

// GetVindexSpec implements the DDLStatement interface
func (node *DropView) GetVindexSpec() *VindexSpec {
return nil
}

// GetFromTables implements the DDLStatement interface
func (node *DDL) GetFromTables() TableNames {
return node.FromTables
Expand All @@ -584,6 +622,11 @@ func (node *CreateView) GetFromTables() TableNames {
return nil
}

// GetFromTables implements the DDLStatement interface
func (node *DropView) GetFromTables() TableNames {
return node.FromTables
}

// GetToTables implements the DDLStatement interface
func (node *DDL) GetToTables() TableNames {
return node.ToTables
Expand All @@ -604,6 +647,11 @@ func (node *CreateTable) GetToTables() TableNames {
return nil
}

// GetToTables implements the DDLStatement interface
func (node *DropView) GetToTables() TableNames {
return nil
}

// GetAutoIncSpec implements the DDLStatement interface
func (node *DDL) GetAutoIncSpec() *AutoIncSpec {
return node.AutoIncSpec
Expand All @@ -624,6 +672,11 @@ func (node *CreateView) GetAutoIncSpec() *AutoIncSpec {
return nil
}

// GetAutoIncSpec implements the DDLStatement interface
func (node *DropView) GetAutoIncSpec() *AutoIncSpec {
return nil
}

// GetVindexCols implements the DDLStatement interface
func (node *DDL) GetVindexCols() []ColIdent {
return node.VindexCols
Expand All @@ -644,6 +697,11 @@ func (node *CreateView) GetVindexCols() []ColIdent {
return nil
}

// GetVindexCols implements the DDLStatement interface
func (node *DropView) GetVindexCols() []ColIdent {
return nil
}

// AffectedTables returns the list table names affected by the DDLStatement.
func (node *DDL) AffectedTables() TableNames {
if node.Action == RenameDDLAction || node.Action == DropDDLAction {
Expand All @@ -670,6 +728,11 @@ func (node *CreateView) AffectedTables() TableNames {
return TableNames{node.ViewName}
}

// AffectedTables returns the list table names affected by the DDLStatement.
func (node *DropView) AffectedTables() TableNames {
return node.FromTables
}

// SetTable implements DDLStatement.
func (node *CreateIndex) SetTable(qualifier string, name string) {
node.Table.Qualifier = NewTableIdent(qualifier)
Expand All @@ -694,6 +757,9 @@ func (node *CreateView) SetTable(qualifier string, name string) {
node.ViewName.Name = NewTableIdent(name)
}

// SetTable implements DDLStatement.
func (node *DropView) SetTable(qualifier string, name string) {}

func (*DropDatabase) iDBDDLStatement() {}
func (*CreateDatabase) iDBDDLStatement() {}
func (*AlterDatabase) iDBDDLStatement() {}
Expand Down Expand Up @@ -2661,3 +2727,12 @@ func (node *LockTables) Format(buf *TrackedBuffer) {
func (node *UnlockTables) Format(buf *TrackedBuffer) {
buf.WriteString("unlock tables")
}

// Format formats the node.
func (node *DropView) Format(buf *TrackedBuffer) {
exists := ""
if node.IfExists {
exists = " if exists"
}
buf.astPrintf(node, "drop view%s %v", exists, node.FromTables)
}
12 changes: 6 additions & 6 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,8 @@ var (
input: "rename table a to b, b to c",
output: "rename table a to b, b to c",
}, {
input: "drop view a",
output: "drop table a",
input: "drop view a,B,c",
output: "drop view a, b, c",
}, {
input: "drop table a",
output: "drop table a",
Expand All @@ -1215,8 +1215,8 @@ var (
input: "drop table if exists a",
output: "drop table if exists a",
}, {
input: "drop view if exists a",
output: "drop table if exists a",
input: "drop view if exists a cascade",
output: "drop view if exists a",
}, {
input: "drop index b on a",
output: "alter table a",
Expand Down Expand Up @@ -1965,10 +1965,10 @@ func TestCaseSensitivity(t *testing.T) {
output: "alter table a",
}, {
input: "drop view A",
output: "drop table a",
output: "drop view a",
}, {
input: "drop view if exists A",
output: "drop table if exists a",
output: "drop view if exists a",
}, {
input: "select /* lock in SHARE MODE */ 1 from t lock in SHARE MODE",
output: "select /* lock in SHARE MODE */ 1 from t lock in share mode",
Expand Down
7 changes: 7 additions & 0 deletions go/vt/sqlparser/rewriter.go

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

Loading