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

Refactor Show plans #7185

Merged
merged 5 commits into from
Dec 16, 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
72 changes: 45 additions & 27 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,40 +753,53 @@ func (node *AlterDatabase) GetDatabaseName() string {
// of SelectStatement.
func (*ParenSelect) iStatement() {}

//ShowInternal will represent all the show statement types.
type ShowInternal interface {
isShowInternal()
SQLNode
}
type (

//ShowLegacy is of ShowInternal type, holds the legacy show ast struct.
type ShowLegacy struct {
Extended string
Type string
OnTable TableName
Table TableName
ShowTablesOpt *ShowTablesOpt
Scope Scope
ShowCollationFilterOpt Expr
}
// ShowInternal will represent all the show statement types.
ShowInternal interface {
isShowInternal()
SQLNode
}

//ShowColumns is of ShowInternal type, holds the show columns statement.
type ShowColumns struct {
Full string
Table TableName
DbName string
Filter *ShowFilter
}
// ShowLegacy is of ShowInternal type, holds the legacy show ast struct.
ShowLegacy struct {
Extended string
Type string
OnTable TableName
Table TableName
ShowTablesOpt *ShowTablesOpt
Scope Scope
ShowCollationFilterOpt Expr
}

// ShowTableStatus is of ShowInternal type, holds SHOW TABLE STATUS queries.
type ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
}
// ShowColumns is of ShowInternal type, holds the show columns statement.
ShowColumns struct {
Full string
Table TableName
DbName string
Filter *ShowFilter
}

// ShowTableStatus is of ShowInternal type, holds SHOW TABLE STATUS queries.
ShowTableStatus struct {
DatabaseName string
Filter *ShowFilter
}

// ShowCommandType represents the show statement type.
ShowCommandType int8

// ShowBasic is of ShowInternal type, holds Simple SHOW queries with a filter.
ShowBasic struct {
Command ShowCommandType
Filter *ShowFilter
}
)

func (*ShowLegacy) isShowInternal() {}
func (*ShowColumns) isShowInternal() {}
func (*ShowTableStatus) isShowInternal() {}
func (*ShowBasic) isShowInternal() {}

// InsertRows represents the rows for an INSERT statement.
type InsertRows interface {
Expand Down Expand Up @@ -2551,6 +2564,11 @@ func (node *ShowTableStatus) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%v", node.Filter)
}

// Format formats the node.
func (node *ShowBasic) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "show%s%v", node.Command.ToString(), node.Filter)
}

// Format formats the node.
func (node *SelectInto) Format(buf *TrackedBuffer) {
if node == nil {
Expand Down
26 changes: 26 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,32 @@ func (ty LockType) ToString() string {
}
}

// ToString returns ShowCommandType as a string
func (ty ShowCommandType) ToString() string {
switch ty {
case Charset:
return CharsetStr
case Collation:
return CollationStr
case Database:
return DatabaseStr
case Function:
return FunctionStr
case Procedure:
return ProcedureStr
case StatusGlobal:
return StatusGlobalStr
case StatusSession:
return StatusSessionStr
case VariableGlobal:
return VariableGlobalStr
case VariableSession:
return VariableSessionStr
default:
return "Unknown ShowCommandType"
}
}

// AtCount represents the '@' count in ColIdent
type AtCount int

Expand Down
29 changes: 27 additions & 2 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const (
// ConvertType.Operator
CharacterSetStr = " character set"
NoOperatorStr = ""
CharsetStr = "charset"

// CollateAndCharset.Type
CollateStr = " collate"
Expand Down Expand Up @@ -194,6 +193,17 @@ const (
ReadLocalStr = "read local"
WriteStr = "write"
LowPriorityWriteStr = "low_priority write"

// ShowCommand Types
CharsetStr = " charset"
CollationStr = " collation"
DatabaseStr = " databases"
FunctionStr = " function status"
ProcedureStr = " procedure status"
StatusGlobalStr = " global status"
StatusSessionStr = " status"
VariableGlobalStr = " global variables"
VariableSessionStr = " variables"
)

// Constants for Enum type - AccessMode
Expand Down Expand Up @@ -387,10 +397,25 @@ const (
CharacterSetType
)

// LockType constants
const (
UnknownType LockType = iota
UnknownLockType LockType = iota
Read
ReadLocal
Write
LowPriorityWrite
)

// ShowCommandType constants
const (
UnknownCommandType ShowCommandType = iota
Charset
Collation
Database
Function
Procedure
StatusGlobal
StatusSession
VariableGlobal
VariableSession
)
20 changes: 10 additions & 10 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,10 @@ var (
output: "show databases like '%'",
}, {
input: "show schemas",
output: "show schemas",
output: "show databases",
}, {
input: "show schemas like '%'",
output: "show schemas like '%'",
output: "show databases like '%'",
}, {
input: "show engine INNODB",
output: "show engine",
Expand Down Expand Up @@ -1344,11 +1344,9 @@ var (
input: "show privileges",
output: "show privileges",
}, {
input: "show procedure code p",
output: "show procedure",
input: "show procedure code p",
}, {
input: "show procedure status",
output: "show procedure",
input: "show procedure status",
}, {
input: "show processlist",
output: "show processlist",
Expand Down Expand Up @@ -1378,7 +1376,7 @@ var (
output: "show global status",
}, {
input: "show session status",
output: "show session status",
output: "show status",
}, {
input: "show table status",
}, {
Expand Down Expand Up @@ -1441,11 +1439,13 @@ var (
output: "show global variables",
}, {
input: "show session variables",
output: "show session variables",
output: "show variables",
}, {
input: "show vitess_keyspaces",
input: "show vitess_keyspaces",
output: "show databases",
}, {
input: "show vitess_keyspaces like '%'",
input: "show vitess_keyspaces like '%'",
output: "show databases like '%'",
}, {
input: "show vitess_shards",
}, {
Expand Down
7 changes: 7 additions & 0 deletions go/vt/sqlparser/rewriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading