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

Add FLUSH as a command and its options #132

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
32 changes: 32 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ func (*Use) iStatement() {}
func (*Begin) iStatement() {}
func (*Commit) iStatement() {}
func (*Rollback) iStatement() {}
func (*Flush) iStatement() {}
func (*OtherRead) iStatement() {}
func (*OtherAdmin) iStatement() {}
func (*BeginEndBlock) iStatement() {}
Expand Down Expand Up @@ -2818,6 +2819,37 @@ func (node *Rollback) Format(buf *TrackedBuffer) {
buf.WriteString("rollback")
}

// FlushOption is used for trailing options for flush statement
type FlushOption struct {
Name string
Channel string
}

// Flush represents a Flush statement.
type Flush struct{
Type string
Options []*FlushOption
}

// Format formats the node.
func (node *Flush) Format(buf *TrackedBuffer) {
buf.WriteString("flush")

var opts []string
for _, opt := range node.Options {
opts = append(opts, strings.ToLower(opt.Name))
if opt.Name == "RELAY LOGS" && opt.Channel != ""{
opts = append(opts, "for channel " + opt.Channel)
}
}

if node.Type == "" {
buf.Myprintf(" %s", strings.Join(opts, " "))
} else {
buf.Myprintf(" %s %s", strings.ToLower(node.Type), strings.Join(opts, " "))
}
}

// OtherRead represents a DESCRIBE, or EXPLAIN statement.
// It should be used only as an indicator. It does not contain
// the full AST for the statement.
Expand Down
15 changes: 15 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,21 @@ var (
}, {
input: "REVOKE PROXY ON UserName FROM Role1, Role2",
output: "revoke proxy on `UserName`@`%` from `Role1`@`%`, `Role2`@`%`",
}, {
input: "FLUSH PRIVILEGES",
output: "flush privileges",
}, {
input: "FLUSH BINARY LOGS",
output: "flush binary logs",
}, {
input: "FLUSH USER_RESOURCES",
output: "flush user_resources",
}, {
input: "FLUSH RELAY LOGS FOR CHANNEL 'connections'",
output: "flush relay logs for channel connections",
}, {
input: "FLUSH LOCAL HOSTS",
output: "flush local hosts",
}, {
input: "SHOW GRANTS",
output: "show grants",
Expand Down
Loading