Skip to content

Commit

Permalink
parser: support show placement ... syntax (#1292)
Browse files Browse the repository at this point in the history
* parser: support `show placement ...` syntax

* Add parser.go
  • Loading branch information
lcwangchao authored Aug 2, 2021
1 parent dd9b189 commit 94275e8
Show file tree
Hide file tree
Showing 4 changed files with 5,682 additions and 5,562 deletions.
22 changes: 22 additions & 0 deletions ast/dml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2528,6 +2528,10 @@ const (
ShowRestores
ShowImports
ShowCreateImport
ShowPlacement
ShowPlacementForDatabase
ShowPlacementForTable
ShowPlacementForPartition
)

const (
Expand All @@ -2551,6 +2555,7 @@ type ShowStmt struct {
Tp ShowStmtType // Databases/Tables/Columns/....
DBName string
Table *TableName // Used for showing columns.
Partition model.CIStr // Used for showing partition.
Column *ColumnName // Used for `desc table column`.
IndexName model.CIStr
Flag int // Some flag parsed from sql, such as FULL.
Expand Down Expand Up @@ -2738,6 +2743,21 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
case ShowCreateImport:
ctx.WriteKeyWord("CREATE IMPORT ")
ctx.WriteName(n.DBName)
case ShowPlacementForDatabase:
ctx.WriteKeyWord("PLACEMENT FOR DATABASE ")
ctx.WriteName(n.DBName)
case ShowPlacementForTable:
ctx.WriteKeyWord("PLACEMENT FOR TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while resotre ShowStmt.Table")
}
case ShowPlacementForPartition:
ctx.WriteKeyWord("PLACEMENT FOR TABLE ")
if err := n.Table.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while resotre ShowStmt.Table")
}
ctx.WriteKeyWord(" PARTITION ")
ctx.WriteName(n.Partition.String())
// ShowTargetFilterable
default:
switch n.Tp {
Expand Down Expand Up @@ -2842,6 +2862,8 @@ func (n *ShowStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("RESTORES")
case ShowImports:
ctx.WriteKeyWord("IMPORTS")
case ShowPlacement:
ctx.WriteKeyWord("PLACEMENT")
default:
return errors.New("Unknown ShowStmt type")
}
Expand Down
Loading

0 comments on commit 94275e8

Please sign in to comment.