Skip to content

Commit

Permalink
Refactor parser to support variations of SHOW INDEX statement
Browse files Browse the repository at this point in the history
Signed-off-by: Saif Alharthi <[email protected]>
  • Loading branch information
saifalharthi committed Apr 3, 2020
1 parent b079336 commit 0c167c1
Show file tree
Hide file tree
Showing 5 changed files with 2,791 additions and 2,756 deletions.
12 changes: 10 additions & 2 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ type (

// Show represents a show statement.
Show struct {
Extended string
Type string
OnTable TableName
Table TableName
Expand Down Expand Up @@ -1167,8 +1168,15 @@ func (node *Show) Format(buf *TrackedBuffer) {
nodeType := strings.ToLower(node.Type)
if (nodeType == "tables" || nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.ShowTablesOpt != nil {
opt := node.ShowTablesOpt
buf.astPrintf(node, "show %s%s", opt.Full, nodeType)
if (nodeType == "columns" || nodeType == "fields" || nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.HasOnTable() {
if node.Extended != "" {
buf.astPrintf(node, "show %s%s", node.Extended, nodeType)
} else {
buf.astPrintf(node, "show %s%s", opt.Full, nodeType)
}
if (nodeType == "columns" || nodeType == "fields") && node.HasOnTable() {
buf.astPrintf(node, " from %v", node.OnTable)
}
if (nodeType == "index" || nodeType == "keys" || nodeType == "indexes") && node.HasOnTable() {
buf.astPrintf(node, " from %v", node.OnTable)
}
if opt.DbName != "" {
Expand Down
9 changes: 6 additions & 3 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,10 +1564,10 @@ var (
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW EXTENDED INDEX FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
output: "show extended index from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED KEYS FROM `AO_E8B6CC_ISSUE_MAPPING` FROM `jiradb`",
output: "show keys from AO_E8B6CC_ISSUE_MAPPING from jiradb",
output: "show extended 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",
Expand All @@ -1579,7 +1579,10 @@ var (
output: "show full tables from jiradb like '%'",
}, {
input: "SHOW EXTENDED INDEXES FROM `AO_E8B6CC_PROJECT_MAPPING` FROM `jiradb`",
output: "show indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}, {
input: "SHOW EXTENDED INDEXES IN `AO_E8B6CC_PROJECT_MAPPING` IN `jiradb`",
output: "show extended indexes from AO_E8B6CC_PROJECT_MAPPING from jiradb",
}}
)

Expand Down
Loading

0 comments on commit 0c167c1

Please sign in to comment.