Skip to content

Commit

Permalink
[parser] parser: add RESUME and BRIEOptionLevel for IMPORT (pingcap#1100
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lance6716 authored and xhebox committed Oct 8, 2021
1 parent f620dd4 commit d86c4d4
Show file tree
Hide file tree
Showing 5 changed files with 8,680 additions and 8,489 deletions.
37 changes: 37 additions & 0 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2398,6 +2398,7 @@ const (
BRIEOptionSkipSchemaFiles
BRIEOptionStrictFormat
BRIEOptionTiKVImporter
BRIEOptionResume
// CSV options
BRIEOptionCSVBackslashEscape
BRIEOptionCSVDelimiter
Expand All @@ -2410,6 +2411,14 @@ const (
BRIECSVHeaderIsColumns = ^uint64(0)
)

type BRIEOptionLevel uint64

const (
BRIEOptionLevelOff BRIEOptionLevel = iota // equals FALSE
BRIEOptionLevelRequired // equals TRUE
BRIEOptionLevelOptional
)

func (kind BRIEKind) String() string {
switch kind {
case BRIEKindBackup:
Expand Down Expand Up @@ -2453,6 +2462,8 @@ func (kind BRIEOptionType) String() string {
return "STRICT_FORMAT"
case BRIEOptionTiKVImporter:
return "TIKV_IMPORTER"
case BRIEOptionResume:
return "RESUME"
case BRIEOptionCSVBackslashEscape:
return "CSV_BACKSLASH_ESCAPE"
case BRIEOptionCSVDelimiter:
Expand All @@ -2472,6 +2483,19 @@ func (kind BRIEOptionType) String() string {
}
}

func (level BRIEOptionLevel) String() string {
switch level {
case BRIEOptionLevelOff:
return "OFF"
case BRIEOptionLevelOptional:
return "OPTIONAL"
case BRIEOptionLevelRequired:
return "REQUIRED"
default:
return ""
}
}

type BRIEOption struct {
Tp BRIEOptionType
StrValue string
Expand Down Expand Up @@ -2561,6 +2585,19 @@ func (n *BRIEStmt) Restore(ctx *format.RestoreCtx) error {
} else {
ctx.WritePlainf("%d", opt.UintValue)
}
case BRIEOptionChecksum, BRIEOptionAnalyze:
switch opt.UintValue {
case 0, 1:
if n.Kind == BRIEKindImport {
ctx.WriteKeyWord(BRIEOptionLevel(opt.UintValue).String())
} else {
ctx.WritePlainf("%d", opt.UintValue)
}
default:
// BACKUP/RESTORE doesn't support this value for now
ctx.WriteKeyWord(BRIEOptionLevel(opt.UintValue).String())
}

default:
ctx.WritePlainf("%d", opt.UintValue)
}
Expand Down
4 changes: 4 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ var tokenMap = map[string]int{
"NULLS": nulls,
"NUMERIC": numericType,
"NVARCHAR": nvarcharType,
"OFF": off,
"OFFSET": offset,
"ON_DUPLICATE": onDuplicate,
"ON": on,
Expand All @@ -496,6 +497,7 @@ var tokenMap = map[string]int{
"OPTIMISTIC": optimistic,
"OPTIMIZE": optimize,
"OPTION": option,
"OPTIONAL": optional,
"OPTIONALLY": optionally,
"OR": or,
"ORDER": order,
Expand Down Expand Up @@ -559,6 +561,7 @@ var tokenMap = map[string]int{
"REPLICAS": replicas,
"REPLICATION": replication,
"REQUIRE": require,
"REQUIRED": required,
"RESET": reset,
"RESPECT": respect,
"RESTART": restart,
Expand All @@ -577,6 +580,7 @@ var tokenMap = map[string]int{
"ROW": row,
"ROWS": rows,
"RTREE": rtree,
"RESUME": resume,
"SAMPLES": samples,
"SAN": san,
"SCHEMA": database,
Expand Down
Loading

0 comments on commit d86c4d4

Please sign in to comment.