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

Support SHOW statements for JIRA #5936

Merged
merged 2 commits into from
Mar 20, 2020
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
15 changes: 8 additions & 7 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,10 +1170,11 @@ func (f *ForeignKeyDefinition) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *Show) Format(buf *TrackedBuffer) {
if (node.Type == "tables" || node.Type == "columns" || node.Type == "fields") && node.ShowTablesOpt != nil {
nodeType := strings.ToLower(node.Type)
if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys") && node.ShowTablesOpt != nil {
opt := node.ShowTablesOpt
buf.Myprintf("show %s%s", opt.Full, node.Type)
if (node.Type == "columns" || node.Type == "fields") && node.HasOnTable() {
buf.Myprintf("show %s%s", opt.Full, nodeType)
if (nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys") && node.HasOnTable() {
buf.Myprintf(" from %v", node.OnTable)
}
if opt.DbName != "" {
Expand All @@ -1183,17 +1184,17 @@ func (node *Show) Format(buf *TrackedBuffer) {
return
}
if node.Scope == "" {
buf.Myprintf("show %s", node.Type)
buf.Myprintf("show %s", nodeType)
} else {
buf.Myprintf("show %s %s", node.Scope, node.Type)
buf.Myprintf("show %s %s", node.Scope, nodeType)
}
if node.HasOnTable() {
buf.Myprintf(" on %v", node.OnTable)
}
if node.Type == "collation" && node.ShowCollationFilterOpt != nil {
if nodeType == "collation" && node.ShowCollationFilterOpt != nil {
buf.Myprintf(" where %v", *node.ShowCollationFilterOpt)
}
if node.Type == "charset" && node.ShowTablesOpt != nil {
if nodeType == "charset" && node.ShowTablesOpt != nil {
buf.Myprintf("%v", node.ShowTablesOpt.Filter)
}
if node.HasTable() {
Expand Down
27 changes: 23 additions & 4 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,14 +1224,12 @@ var (
input: "show grants for 'root@localhost'",
output: "show grants",
}, {
input: "show index from table",
output: "show index",
input: "show index from t",
}, {
input: "show indexes from table",
output: "show indexes",
}, {
input: "show keys from table",
output: "show keys",
input: "show keys from t",
}, {
input: "show master status",
output: "show master",
Expand Down Expand Up @@ -1541,6 +1539,27 @@ var (
input: "select status() from t", // should not escape function names that are keywords
}, {
input: "select * from `weird table name`",
}, {
input: "SHOW FULL TABLES FROM `jiradb` LIKE 'AO_E8B6CC_ISSUE_MAPPING'",
output: "show full tables from jiradb like 'AO_E8B6CC_ISSUE_MAPPING'",
}, {
input: "SHOW FULL COLUMNS FROM AO_E8B6CC_ISSUE_MAPPING FROM jiradb LIKE '%'",
output: "show full columns from AO_E8B6CC_ISSUE_MAPPING from jiradb like '%'",
}, {
input: "SHOW KEYS FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show keys from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW CREATE TABLE `jiradb`.`AO_E8B6CC_ISSUE_MAPPING`",
output: "show create table jiradb.AO_E8B6CC_ISSUE_MAPPING",
}, {
input: "SHOW INDEX FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show index from AO_E8B6CC_ISSUE_MAPPING from jiradb",
}, {
input: "SHOW FULL TABLES FROM `jiradb` LIKE '%'",
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW INDEX FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}}
)

Expand Down
Loading