Skip to content
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
106 changes: 106 additions & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -3174,6 +3174,21 @@ const (
ShowDistributions
ShowDistributionJobs
ShowAffinity
ShowBinaryLogs
ShowBinlogEvents
ShowRelaylogEvents
ShowReplicas
ShowEngineStatus
ShowEngineMutex
ShowCreateEvent
ShowCreateFunction
ShowCreateTrigger
ShowCreateLibrary
ShowCreateMaskingPolicy
ShowFunctionCode
ShowProcedureCode
ShowLibraryStatus
ShowParseTree
// showTpCount is the count of all kinds of `SHOW` statements.
showTpCount
)
Expand Down Expand Up @@ -3230,6 +3245,14 @@ type ShowStmt struct {
ImportJobRaw bool // Used for `SHOW RAW IMPORT JOB(S)` syntax

DistributionJobID *int64 // Used for `SHOW DISTRIBUTION JOB <ID>` syntax

Engine string // Used for `SHOW ENGINE <name> STATUS|MUTEX` syntax

LogName string // Used for `SHOW BINLOG|RELAYLOG EVENTS IN '<log>'` syntax
Position *int64 // Used for `SHOW BINLOG|RELAYLOG EVENTS ... FROM <pos>` syntax
ChannelName string // Used for `SHOW BINLOG|RELAYLOG EVENTS ... FOR CHANNEL '<channel>'` syntax

ParseTreeStmt StmtNode // Used for `SHOW PARSE_TREE <statement>` syntax
}

// Restore implements Node interface.
Expand Down Expand Up @@ -3272,6 +3295,57 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
switch n.Tp {
case ShowBinlogStatus:
ctx.WriteKeyWord("BINARY LOG STATUS")
case ShowBinaryLogs:
ctx.WriteKeyWord("BINARY LOGS")
case ShowBinlogEvents, ShowRelaylogEvents:
if n.Tp == ShowBinlogEvents {
ctx.WriteKeyWord("BINLOG EVENTS")
} else {
ctx.WriteKeyWord("RELAYLOG EVENTS")
}
if n.LogName != "" {
ctx.WriteKeyWord(" IN ")
ctx.WriteString(n.LogName)
}
if n.Position != nil {
ctx.WriteKeyWord(" FROM ")
ctx.WritePlainf("%d", *n.Position)
}
if n.Limit != nil {
ctx.WritePlain(" ")
if err := n.Limit.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Limit")
}
}
if n.ChannelName != "" {
ctx.WriteKeyWord(" FOR CHANNEL ")
ctx.WriteString(n.ChannelName)
}
case ShowReplicas:
ctx.WriteKeyWord("REPLICAS")
case ShowEngineStatus:
ctx.WriteKeyWord("ENGINE ")
ctx.WriteName(n.Engine)
ctx.WriteKeyWord(" STATUS")
case ShowEngineMutex:
ctx.WriteKeyWord("ENGINE ")
ctx.WriteName(n.Engine)
ctx.WriteKeyWord(" MUTEX")
case ShowFunctionCode:
ctx.WriteKeyWord("FUNCTION CODE ")
if err := n.Procedure.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Procedure")
}
case ShowProcedureCode:
ctx.WriteKeyWord("PROCEDURE CODE ")
if err := n.Procedure.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Procedure")
}
case ShowParseTree:
ctx.WriteKeyWord("PARSE_TREE ")
if err := n.ParseTreeStmt.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.ParseTreeStmt")
}
case ShowCreateTable:
ctx.WriteKeyWord("CREATE TABLE ")
if err := n.Table.Restore(ctx); err != nil {
Expand Down Expand Up @@ -3309,6 +3383,29 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
if err := n.User.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.User")
}
case ShowCreateEvent:
ctx.WriteKeyWord("CREATE EVENT ")
if err := n.Table.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Table")
}
case ShowCreateFunction:
ctx.WriteKeyWord("CREATE FUNCTION ")
if err := n.Procedure.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Procedure")
}
case ShowCreateTrigger:
ctx.WriteKeyWord("CREATE TRIGGER ")
if err := n.Table.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Table")
}
case ShowCreateLibrary:
ctx.WriteKeyWord("CREATE LIBRARY ")
if err := n.Table.Restore(ctx); err != nil {
return annotate(err, "An error occurred while restore ShowStmt.Table")
}
case ShowCreateMaskingPolicy:
ctx.WriteKeyWord("CREATE MASKING POLICY ")
ctx.WriteName(n.DBName)
case ShowMaskingPolicies:
ctx.WriteKeyWord("MASKING POLICIES FOR ")
if err := n.Table.Restore(ctx); err != nil {
Expand Down Expand Up @@ -3539,6 +3636,8 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("PROCEDURE STATUS")
case ShowFunctionStatus:
ctx.WriteKeyWord("FUNCTION STATUS")
case ShowLibraryStatus:
ctx.WriteKeyWord("LIBRARY STATUS")
case ShowEvents:
ctx.WriteKeyWord("EVENTS")
restoreShowDatabaseNameOpt()
Expand Down Expand Up @@ -3651,6 +3750,13 @@ func (n *ShowStmt) Accept(v Visitor) (Node, bool) {
}
n.Limit = node.(*Limit)
}
if n.ParseTreeStmt != nil {
node, ok := n.ParseTreeStmt.Accept(v)
if !ok {
return n, false
}
n.ParseTreeStmt = node.(StmtNode)
}
return v.Leave(n)
}

Expand Down
56 changes: 56 additions & 0 deletions ast/sem.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,34 @@ const (
ShowDistributionJobsCommand = "SHOW DISTRIBUTION JOB"
// ShowAffinityCommand represents SHOW AFFINITY statement
ShowAffinityCommand = "SHOW AFFINITY"
// ShowBinaryLogsCommand represents SHOW BINARY LOGS statement
ShowBinaryLogsCommand = "SHOW BINARY LOGS"
// ShowBinlogEventsCommand represents SHOW BINLOG EVENTS statement
ShowBinlogEventsCommand = "SHOW BINLOG EVENTS"
// ShowRelaylogEventsCommand represents SHOW RELAYLOG EVENTS statement
ShowRelaylogEventsCommand = "SHOW RELAYLOG EVENTS"
// ShowReplicasCommand represents SHOW REPLICAS statement
ShowReplicasCommand = "SHOW REPLICAS"
// ShowEngineCommand represents SHOW ENGINE statement
ShowEngineCommand = "SHOW ENGINE"
// ShowCreateEventCommand represents SHOW CREATE EVENT statement
ShowCreateEventCommand = "SHOW CREATE EVENT"
// ShowCreateFunctionCommand represents SHOW CREATE FUNCTION statement
ShowCreateFunctionCommand = "SHOW CREATE FUNCTION"
// ShowCreateTriggerCommand represents SHOW CREATE TRIGGER statement
ShowCreateTriggerCommand = "SHOW CREATE TRIGGER"
// ShowCreateLibraryCommand represents SHOW CREATE LIBRARY statement
ShowCreateLibraryCommand = "SHOW CREATE LIBRARY"
// ShowCreateMaskingPolicyCommand represents SHOW CREATE MASKING POLICY statement
ShowCreateMaskingPolicyCommand = "SHOW CREATE MASKING POLICY"
// ShowFunctionCodeCommand represents SHOW FUNCTION CODE statement
ShowFunctionCodeCommand = "SHOW FUNCTION CODE"
// ShowProcedureCodeCommand represents SHOW PROCEDURE CODE statement
ShowProcedureCodeCommand = "SHOW PROCEDURE CODE"
// ShowLibraryStatusCommand represents SHOW LIBRARY STATUS statement
ShowLibraryStatusCommand = "SHOW LIBRARY STATUS"
// ShowParseTreeCommand represents SHOW PARSE_TREE statement
ShowParseTreeCommand = "SHOW PARSE_TREE"
)

// Admin Commands
Expand Down Expand Up @@ -872,6 +900,34 @@ func (n *ShowStmt) SEMCommand() string {
return ShowDistributionJobsCommand
case ShowAffinity:
return ShowAffinityCommand
case ShowBinaryLogs:
return ShowBinaryLogsCommand
case ShowBinlogEvents:
return ShowBinlogEventsCommand
case ShowRelaylogEvents:
return ShowRelaylogEventsCommand
case ShowReplicas:
return ShowReplicasCommand
case ShowEngineStatus, ShowEngineMutex:
return ShowEngineCommand
case ShowCreateEvent:
return ShowCreateEventCommand
case ShowCreateFunction:
return ShowCreateFunctionCommand
case ShowCreateTrigger:
return ShowCreateTriggerCommand
case ShowCreateLibrary:
return ShowCreateLibraryCommand
case ShowCreateMaskingPolicy:
return ShowCreateMaskingPolicyCommand
case ShowFunctionCode:
return ShowFunctionCodeCommand
case ShowProcedureCode:
return ShowProcedureCodeCommand
case ShowLibraryStatus:
return ShowLibraryStatusCommand
case ShowParseTree:
return ShowParseTreeCommand
default:
return UnknownCommand
}
Expand Down
5 changes: 5 additions & 0 deletions parser/keyword_classes.go

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

5 changes: 5 additions & 0 deletions parser/keywords.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ var Keywords = []KeywordsType{
{"CLUSTER", false, "unreserved"},
{"CLUSTERED", false, "unreserved"},
{"COALESCE", false, "unreserved"},
{"CODE", false, "unreserved"},
{"COLLATION", false, "unreserved"},
{"COLUMNAR", false, "unreserved"},
{"COLUMNS", false, "unreserved"},
Expand Down Expand Up @@ -447,6 +448,7 @@ var Keywords = []KeywordsType{
{"LEAVES", false, "unreserved"},
{"LESS", false, "unreserved"},
{"LEVEL", false, "unreserved"},
{"LIBRARY", false, "unreserved"},
{"LIST", false, "unreserved"},
{"LOAD_STATS", false, "unreserved"},
{"LOCAL", false, "unreserved"},
Expand Down Expand Up @@ -474,6 +476,7 @@ var Keywords = []KeywordsType{
{"MODE", false, "unreserved"},
{"MODIFY", false, "unreserved"},
{"MONTH", false, "unreserved"},
{"MUTEX", false, "unreserved"},
{"NAMES", false, "unreserved"},
{"NATIONAL", false, "unreserved"},
{"NCHAR", false, "unreserved"},
Expand Down Expand Up @@ -508,6 +511,7 @@ var Keywords = []KeywordsType{
{"PAGE_COMPRESSION_LEVEL", false, "unreserved"},
{"PARALLEL", false, "unreserved"},
{"PARSER", false, "unreserved"},
{"PARSE_TREE", false, "unreserved"},
{"PARTIAL", false, "unreserved"},
{"PARTITIONING", false, "unreserved"},
{"PARTITIONS", false, "unreserved"},
Expand Down Expand Up @@ -543,6 +547,7 @@ var Keywords = []KeywordsType{
{"RECOVER", false, "unreserved"},
{"REDUNDANT", false, "unreserved"},
{"REFRESH", false, "unreserved"},
{"RELAYLOG", false, "unreserved"},
{"RELOAD", false, "unreserved"},
{"REMOVE", false, "unreserved"},
{"REORGANIZE", false, "unreserved"},
Expand Down
4 changes: 2 additions & 2 deletions parser/keywords_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestKeywords(t *testing.T) {
}

func TestKeywordsLength(t *testing.T) {
if !reflect.DeepEqual(707, len(parser.Keywords)) {
t.Fatalf("got %v, want %v", len(parser.Keywords), 707)
if !reflect.DeepEqual(712, len(parser.Keywords)) {
t.Fatalf("got %v, want %v", len(parser.Keywords), 712)
}

reservedNr := 0
Expand Down
5 changes: 5 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ var tokenMap = map[string]int{
"CLUSTERED": clustered,
"CMSKETCH": cmSketch,
"COALESCE": coalesce,
"CODE": code,
"COLLATE": collate,
"COLLATION": collation,
"COLUMN_FORMAT": columnFormat,
Expand Down Expand Up @@ -531,6 +532,7 @@ var tokenMap = map[string]int{
"LEFT": left,
"LESS": less,
"LEVEL": level,
"LIBRARY": library,
"LIKE": like,
"LIMIT": limit,
"LITE": lite,
Expand Down Expand Up @@ -584,6 +586,7 @@ var tokenMap = map[string]int{
"MODIFY": modify,
"MONITOR": monitor,
"MONTH": month,
"MUTEX": mutex,
"NAMES": names,
"NATIONAL": national,
"NATURAL": natural,
Expand Down Expand Up @@ -640,6 +643,7 @@ var tokenMap = map[string]int{
"PAGE_COMPRESSION_LEVEL": pageCompressionLevel,
"PARALLEL": parallel,
"PARSER": parser,
"PARSE_TREE": parseTree,
"PARTIAL": partial,
"PARTITION": partition,
"PARTITIONING": partitioning,
Expand Down Expand Up @@ -700,6 +704,7 @@ var tokenMap = map[string]int{
"REGEXP": regexpKwd,
"REGION": region,
"REGIONS": regions,
"RELAYLOG": relaylog,
"RELEASE": release,
"RELOAD": reload,
"REMOVE": remove,
Expand Down
Loading
Loading