Skip to content

Commit

Permalink
update: 添加分区表与非分区表转换语法支持 (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanchuanchuan committed Apr 5, 2022
1 parent 767bf4f commit 37c624b
Show file tree
Hide file tree
Showing 11 changed files with 7,106 additions and 6,117 deletions.
553 changes: 538 additions & 15 deletions ast/ddl.go

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,20 @@ func (n *DropBindingStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// Extended statistics types.
const (
StatsTypeCardinality uint8 = iota
StatsTypeDependency
StatsTypeCorrelation
)

// StatisticsSpec is the specification for ADD /DROP STATISTICS.
type StatisticsSpec struct {
StatsName string
StatsType uint8
Columns []*ColumnName
}

// DoStmt is the struct for DO statement.
type DoStmt struct {
stmtNode
Expand Down
36 changes: 36 additions & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ const (
RestoreNameBackQuotes

RestoreSpacesAroundBinaryOperation
RestoreBracketAroundBinaryOperation

RestoreStringWithoutCharset
RestoreStringWithoutDefaultCharset

RestoreTiDBSpecialComment
)

const (
Expand Down Expand Up @@ -278,6 +284,22 @@ func (rf RestoreFlags) HasSpacesAroundBinaryOperationFlag() bool {
return rf.has(RestoreSpacesAroundBinaryOperation)
}

func (rf RestoreFlags) HasRestoreBracketAroundBinaryOperation() bool {
return rf.has(RestoreBracketAroundBinaryOperation)
}

func (rf RestoreFlags) HasStringWithoutDefaultCharset() bool {
return rf.has(RestoreStringWithoutDefaultCharset)
}

func (rf RestoreFlags) HasStringWithoutCharset() bool {
return rf.has(RestoreStringWithoutCharset)
}

func (rf RestoreFlags) HasTiDBSpecialCommentFlag() bool {
return rf.has(RestoreTiDBSpecialComment)
}

// RestoreCtx is `Restore` context to hold flags and writer.
type RestoreCtx struct {
Flags RestoreFlags
Expand All @@ -302,6 +324,20 @@ func (ctx *RestoreCtx) WriteKeyWord(keyWord string) {
fmt.Fprint(ctx.In, keyWord)
}

func (ctx *RestoreCtx) WriteWithSpecialComments(featureID string, fn func()) {
if !ctx.Flags.HasTiDBSpecialCommentFlag() {
fn()
return
}
ctx.WritePlain("/*T!")
if len(featureID) != 0 {
ctx.WritePlainf("[%s]", featureID)
}
ctx.WritePlain(" ")
fn()
ctx.WritePlain(" */")
}

// WriteString writes the string into writer
// `str` may be wrapped in quotes and escaped according to RestoreFlags.
func (ctx *RestoreCtx) WriteString(str string) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 // indirect
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
github.com/etcd-io/gofail v0.0.0-20180808172546-51ce9a71510a // indirect
github.com/etcd-io/gofail v0.0.0-20180808172546-51ce9a71510a
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-sql-driver/mysql v1.4.1
github.com/gofrs/uuid v3.2.0+incompatible
Expand Down
4 changes: 4 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var tokenMap = map[string]int{
"AS": as,
"ASC": asc,
"ASCII": ascii,
"ATTRIBUTES": attributes,
"AUTO_INCREMENT": autoIncrement,
"AUTO_RANDOM": autoRandom,
"AUTO_RANDOM_BASE": autoRandomBase,
Expand Down Expand Up @@ -396,6 +397,7 @@ var tokenMap = map[string]int{
"PACK_KEYS": packKeys,
"PARSER": parser,
"PARTITION": partition,
"PARTITIONING": partitioning,
"PARTITIONS": partitions,
"PASSWORD": password,
"PLUGINS": plugins,
Expand All @@ -422,7 +424,9 @@ var tokenMap = map[string]int{
"REFERENCES": references,
"REGEXP": regexpKwd,
"RELOAD": reload,
"REMOVE": remove,
"RENAME": rename,
"REORGANIZE": reorganize,
"REPAIR": repair,
"REPEAT": repeat,
"REPEATABLE": repeatable,
Expand Down
Loading

0 comments on commit 37c624b

Please sign in to comment.