Skip to content

Commit

Permalink
Merge pull request #5936 from planetscale/sa-jira-show-support
Browse files Browse the repository at this point in the history
Support SHOW statements for JIRA
  • Loading branch information
systay authored Mar 20, 2020
2 parents de816f5 + 923531b commit 2292f27
Show file tree
Hide file tree
Showing 6 changed files with 2,141 additions and 2,085 deletions.
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

0 comments on commit 2292f27

Please sign in to comment.