Skip to content

Commit

Permalink
go/vt/sqlparser: Parse KILL {,CONNECTION,QUERY} statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
reltuk committed Dec 10, 2021
1 parent ec8558d commit 1d20a87
Show file tree
Hide file tree
Showing 5 changed files with 6,201 additions and 6,112 deletions.
24 changes: 24 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -5542,6 +5542,30 @@ func (node *UnlockTables) walkSubtree(visit Visit) error {
return nil
}

type Kill struct {
Connection bool
ConnID Expr
}

func (k *Kill) Format(buf *TrackedBuffer) {
buf.WriteString("kill ")
if k.Connection {
buf.WriteString("connection ")
} else {
buf.WriteString("query ")
}
buf.Myprintf("%v", k.ConnID)
}

func (*Kill) iStatement() {}

func (k *Kill) walkSubtree(visit Visit) error {
if k == nil {
return nil
}
return Walk(visit, k.ConnID)
}

func compliantName(in string) string {
var buf strings.Builder
for i, c := range in {
Expand Down
7 changes: 6 additions & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2227,8 +2227,13 @@ var (
}, {
input: "SHOW GRANTS FOR UserName USING role1, role2",
output: "show grants for `UserName`@`%` using `role1`@`%`, `role2`@`%`",
}, {
input: "kill query 123",
output: "kill query 123",
}, {
input: "kill connection 423",
output: "kill connection 423",
},

}
// Any tests that contain multiple statements within the body (such as BEGIN/END blocks) should go here.
// validSQL is used by TestParseNextValid, which expects a semicolon to mean the end of a full statement.
Expand Down
Loading

0 comments on commit 1d20a87

Please sign in to comment.