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

Implement DROP VIEW statement #155

Merged
Merged
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
14 changes: 14 additions & 0 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (CreateDatabase) isStatement() {}
func (CreateTable) isStatement() {}
func (CreateSequence) isStatement() {}
func (CreateView) isStatement() {}
func (DropView) isStatement() {}
func (CreateIndex) isStatement() {}
func (CreateVectorIndex) isStatement() {}
func (CreateRole) isStatement() {}
Expand Down Expand Up @@ -256,6 +257,7 @@ type DDL interface {
func (CreateDatabase) isDDL() {}
func (CreateTable) isDDL() {}
func (CreateView) isDDL() {}
func (DropView) isDDL() {}
func (CreateSequence) isDDL() {}
func (AlterTable) isDDL() {}
func (DropTable) isDDL() {}
Expand Down Expand Up @@ -1797,6 +1799,18 @@ type CreateView struct {
Query QueryExpr
}

// DropView is DROP VIEW statement node.
//
// DROP VIEW {{.Name | sql}}
type DropView struct {
// pos = Drop
// end = Name.end

Drop token.Pos

Name *Ident
}

// AlterTable is ALTER TABLE statement node.
//
// ALTER TABLE {{.Name | sql}} {{.TableAlteration | sql}}
Expand Down
1 change: 1 addition & 0 deletions ast/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func TestDDL(t *testing.T) {
DDL(&AlterSequence{}).isDDL()
DDL(&DropSequence{}).isDDL()
DDL(&CreateView{}).isDDL()
DDL(&DropView{}).isDDL()
DDL(&AlterTable{}).isDDL()
DDL(&DropTable{}).isDDL()
DDL(&CreateIndex{}).isDDL()
Expand Down
3 changes: 3 additions & 0 deletions ast/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ func (c *CreateView) End() token.Pos {
return c.Query.End()
}

func (d *DropView) Pos() token.Pos { return d.Drop }
func (d *DropView) End() token.Pos { return d.Name.End() }

func (c *ColumnDef) Pos() token.Pos {
return c.Name.Pos()
}
Expand Down
2 changes: 2 additions & 0 deletions ast/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,8 @@ func (c *CreateView) SQL() string {
return sql
}

func (d *DropView) SQL() string { return "DROP VIEW " + d.Name.SQL() }

func (c *ColumnDef) SQL() string {
sql := c.Name.SQL() + " " + c.Type.SQL()
if c.NotNull {
Expand Down
12 changes: 12 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,8 @@ func (p *Parser) parseDDL() ast.DDL {
return p.parseDropVectorIndex(pos)
case p.Token.IsKeywordLike("SEQUENCE"):
return p.parseDropSequence(pos)
case p.Token.IsKeywordLike("VIEW"):
return p.parseDropView(pos)
case p.Token.IsKeywordLike("ROLE"):
return p.parseDropRole(pos)
case p.Token.IsKeywordLike("CHANGE"):
Expand Down Expand Up @@ -2314,6 +2316,16 @@ func (p *Parser) parseCreateView(pos token.Pos) *ast.CreateView {
}
}

func (p *Parser) parseDropView(pos token.Pos) *ast.DropView {
p.expectKeywordLike("VIEW")
name := p.parseIdent()

return &ast.DropView{
Drop: pos,
Name: name,
}
}

func (p *Parser) parseColumnDef() *ast.ColumnDef {
name := p.parseIdent()
t, notNull, null := p.parseTypeNotNull()
Expand Down
1 change: 1 addition & 0 deletions testdata/input/ddl/drop_view.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP VIEW SingersView
14 changes: 14 additions & 0 deletions testdata/result/ddl/drop_view.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- drop_view.sql
DROP VIEW SingersView
--- AST
&ast.DropView{
Drop: 0,
Name: &ast.Ident{
NamePos: 10,
NameEnd: 21,
Name: "SingersView",
},
}

--- SQL
DROP VIEW SingersView
14 changes: 14 additions & 0 deletions testdata/result/statement/drop_view.sql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- drop_view.sql
DROP VIEW SingersView
--- AST
&ast.DropView{
Drop: 0,
Name: &ast.Ident{
NamePos: 10,
NameEnd: 21,
Name: "SingersView",
},
}

--- SQL
DROP VIEW SingersView
Loading