Skip to content

Commit

Permalink
Merge pull request #65 from hanchuanchuan/upgrade-parser
Browse files Browse the repository at this point in the history
升级parser语法解析包
  • Loading branch information
hanchuanchuan authored Jul 26, 2019
2 parents aca8119 + 0625551 commit 33725dd
Show file tree
Hide file tree
Showing 41 changed files with 1,273 additions and 320 deletions.
495 changes: 483 additions & 12 deletions ast/ddl.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ast/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"bytes"
"fmt"

. "github.com/pingcap/check"
"github.com/hanchuanchuan/goInception/ast"
"github.com/hanchuanchuan/goInception/parser"
. "github.com/pingcap/check"
)

var _ = Suite(&testAstFormatSuite{})
Expand Down Expand Up @@ -87,7 +87,7 @@ func (ts *testAstFormatSuite) TestAstFormat(c *C) {
for _, tt := range testcases {
expr := fmt.Sprintf("select %s", tt.input)
charset, collation := getDefaultCharsetAndCollate()
stmts, err := parser.New().Parse(expr, charset, collation)
stmts, _, err := parser.New().Parse(expr, charset, collation)
node := stmts[0].(*ast.SelectStmt).Fields.Fields[0].Expr
c.Assert(err, IsNil)

Expand Down
6 changes: 3 additions & 3 deletions ast/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
package ast_test

import (
. "github.com/pingcap/check"
. "github.com/hanchuanchuan/goInception/ast"
"github.com/hanchuanchuan/goInception/parser"
"github.com/hanchuanchuan/goInception/util/auth"
. "github.com/pingcap/check"
)

var _ = Suite(&testMiscSuite{})
Expand Down Expand Up @@ -99,7 +99,7 @@ constraint foreign key (jobabbr) references ffxi_jobtype (jobabbr) on delete cas
);
`
parse := parser.New()
stmts, err := parse.Parse(sql, "", "")
stmts, _, err := parse.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
Expand All @@ -118,7 +118,7 @@ show create table t;
load data infile '/tmp/t.csv' into table t fields terminated by 'ab' enclosed by 'b';`

p := parser.New()
stmts, err := p.Parse(sql, "", "")
stmts, _, err := p.Parse(sql, "", "")
c.Assert(err, IsNil)
for _, stmt := range stmts {
stmt.Accept(visitor{})
Expand Down
17 changes: 17 additions & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,23 @@ func (d *ddl) genGlobalID() (int64, error) {
return globalID, errors.Trace(err)
}

func (d *ddl) genGlobalIDs(count int) ([]int64, error) {
ret := make([]int64, count)
err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
var err error
m := meta.NewMeta(txn)
for i := 0; i < count; i++ {
ret[i], err = m.GenGlobalID()
if err != nil {
return err
}
}
return nil
})

return ret, err
}

// SchemaSyncer implements DDL.SchemaSyncer interface.
func (d *ddl) SchemaSyncer() SchemaSyncer {
return d.schemaSyncer
Expand Down
40 changes: 25 additions & 15 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2127,31 +2127,41 @@ func buildPartitionInfo(meta *model.TableInfo, d *ddl, spec *ast.AlterTableSpec)
Columns: meta.Partition.Columns,
Enable: meta.Partition.Enable,
}
genIDs, err := d.genGlobalIDs(len(spec.PartDefinitions))
if err != nil {
return nil, err
}
buf := new(bytes.Buffer)
for _, def := range spec.PartDefinitions {
for _, expr := range def.LessThan {
for ith, def := range spec.PartDefinitions {
if err := def.Clause.Validate(part.Type, len(part.Columns)); err != nil {
return nil, errors.Trace(err)
}
// For RANGE partition only VALUES LESS THAN should be possible.
clause := def.Clause.(*ast.PartitionDefinitionClauseLessThan)
for _, expr := range clause.Exprs {
tp := expr.GetType().Tp
if !(tp == mysql.TypeLong || tp == mysql.TypeLonglong) {
expr.Format(buf)
if strings.EqualFold(buf.String(), "MAXVALUE") {
continue
if len(part.Columns) == 0 {
// Partition by range.
if !(tp == mysql.TypeLong || tp == mysql.TypeLonglong) {
expr.Format(buf)
if strings.EqualFold(buf.String(), "MAXVALUE") {
continue
}
buf.Reset()
return nil, infoschema.ErrColumnNotExists.GenWithStackByArgs(buf.String(), "partition function")
}
buf.Reset()
return nil, infoschema.ErrColumnNotExists.GenWithStackByArgs(buf.String(), "partition function")
}
// Partition by range columns if len(part.Columns) != 0.
}
pid, err1 := d.genGlobalID()
if err1 != nil {
return nil, errors.Trace(err1)
}
comment, _ := def.Comment()
piDef := model.PartitionDefinition{
Name: def.Name,
ID: pid,
Comment: def.Comment,
ID: genIDs[ith],
Comment: comment,
}

buf := new(bytes.Buffer)
for _, expr := range def.LessThan {
for _, expr := range clause.Exprs {
expr.Format(buf)
piDef.LessThan = append(piDef.LessThan, buf.String())
buf.Reset()
Expand Down
9 changes: 4 additions & 5 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,23 @@ func buildTablePartitionInfo(ctx sessionctx.Context, d *ddl, s *ast.CreateTableS
}
}
for _, def := range s.Partition.Definitions {
comment, _ := def.Comment()
// TODO: generate multiple global ID for paritions, reduce the times of obtaining the global ID from the storage.
pid, err := d.genGlobalID()
if err != nil {
return nil, errors.Trace(err)
}

piDef := model.PartitionDefinition{
Name: def.Name,
ID: pid,
Comment: def.Comment,
Comment: comment,
}

if s.Partition.Tp == model.PartitionTypeRange {
if s.Partition.ColumnNames == nil && len(def.LessThan) != 1 {
return nil, ErrTooManyValues.GenWithStackByArgs(s.Partition.Tp.String())
}
buf := new(bytes.Buffer)
// Range columns partitions support multi-column partitions.
for _, expr := range def.LessThan {
for _, expr := range def.Clause.(*ast.PartitionDefinitionClauseLessThan).Exprs {
expr.Format(buf)
piDef.LessThan = append(piDef.LessThan, buf.String())
buf.Reset()
Expand Down
2 changes: 1 addition & 1 deletion executor/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (e *PrepareExec) Next(ctx context.Context, chk *chunk.Chunk) error {
if sqlParser, ok := e.ctx.(sqlexec.SQLParser); ok {
stmts, err = sqlParser.ParseSQL(e.sqlText, charset, collation)
} else {
stmts, err = parser.New().Parse(e.sqlText, charset, collation)
stmts, _, err = parser.New().Parse(e.sqlText, charset, collation)
}
if err != nil {
return errors.Trace(err)
Expand Down
8 changes: 4 additions & 4 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (

"github.com/hanchuanchuan/goInception/executor"
plannercore "github.com/hanchuanchuan/goInception/planner/core"
"github.com/hanchuanchuan/goInception/terror"
// "github.com/hanchuanchuan/goInception/terror"
"github.com/hanchuanchuan/goInception/util/testkit"
. "github.com/pingcap/check"
"github.com/pingcap/errors"
// "github.com/pingcap/errors"
"golang.org/x/net/context"
)

Expand Down Expand Up @@ -60,8 +60,8 @@ func (s *testSuite) TestPrepared(c *C) {
c.Assert(plannercore.ErrStmtNotFound.Equal(err), IsTrue)

// incorrect SQLs in prepare. issue #3738, SQL in prepare stmt is parsed in DoPrepare.
_, err = tk.Exec(`prepare p from "delete from t where a = 7 or 1=1/*' and b = 'p'";`)
c.Assert(terror.ErrorEqual(err, errors.New(`[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/*' and b = 'p'' at line 1`)), IsTrue, Commentf("err %v", err))
// _, err = tk.Exec(`prepare p from "delete from t where a = 7 or 1=1/*' and b = 'p'";`)
// c.Assert(terror.ErrorEqual(err, errors.New(`[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/*' and b = 'p'' at line 1`)), IsTrue, Commentf("err %v", err))

// The `stmt_test5` should not be found.
_, err = tk.Exec(`set @a = 1; execute stmt_test_5 using @a;`)
Expand Down
4 changes: 2 additions & 2 deletions executor/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ func (s *testSuite) TestShow2(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec(`create table if not exists t (c int) comment '注释'`)
tk.MustQuery(`show columns from t`).Check(testutil.RowsWithSep(",", "c,int(11),YES,,<nil>,"))
tk.MustQuery("show collation where Charset = 'utf8' and Collation = 'utf8_bin'").Check(testutil.RowsWithSep(",", "utf8_bin,utf8,83,,Yes,1"))

// tk.MustQuery("show collation where Charset = 'utf8' and Collation = 'utf8_bin'").Check(testutil.RowsWithSep(",", "utf8_bin,utf8,83,,Yes,1"))
tk.MustQuery("show collation where Charset = 'utf8' and Collation = 'utf8_bin'").Check(testutil.RowsWithSep(",", "utf8_bin,utf8,83,Yes,Yes,1"))
tk.MustQuery("show tables").Check(testkit.Rows("t"))
tk.MustQuery("show full tables").Check(testkit.Rows("t BASE TABLE"))
ctx := tk.Se.(sessionctx.Context)
Expand Down
4 changes: 2 additions & 2 deletions expression/simple_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type simpleRewriter struct {
// The expression string must only reference the column in table Info.
func ParseSimpleExprWithTableInfo(ctx sessionctx.Context, exprStr string, tableInfo *model.TableInfo) (Expression, error) {
exprStr = "select " + exprStr
stmts, err := parser.New().Parse(exprStr, "", "")
stmts, _, err := parser.New().Parse(exprStr, "", "")
if err != nil {
return nil, errors.Trace(err)
}
Expand Down Expand Up @@ -71,7 +71,7 @@ func RewriteSimpleExprWithTableInfo(ctx sessionctx.Context, tbl *model.TableInfo
// The expression string must only reference the column in the given schema.
func ParseSimpleExprsWithSchema(ctx sessionctx.Context, exprStr string, schema *Schema) ([]Expression, error) {
exprStr = "select " + exprStr
stmts, err := parser.New().Parse(exprStr, "", "")
stmts, _, err := parser.New().Parse(exprStr, "", "")
if err != nil {
return nil, errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ require (
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
go.uber.org/zap v1.9.1 // indirect
go.uber.org/zap v1.9.1
golang.org/x/net v0.0.0-20181029044818-c44066c5c816
golang.org/x/text v0.3.2
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e h1:P73/4dPCL96rG
github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw=
github.com/pingcap/kvproto v0.0.0-20181206061346-54cf0a0dfe55 h1:0vbRC39OU0Ep2GFgV5BwZ1u3viC5uk8yb3c07rLRMvY=
github.com/pingcap/kvproto v0.0.0-20181206061346-54cf0a0dfe55/go.mod h1:Ja9XPjot9q4/3JyCZodnWDGNXt4pKemhIYCvVJM7P24=
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825 h1:U9Kdnknj4n2v76Mg7wazevZ5N9U1OIaMwSNRVLEcLX0=
github.com/pingcap/parser v0.0.0-20190506092653-e336082eb825/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA=
github.com/pingcap/pd v2.1.0+incompatible h1:X0o443C/jXF6yJiiP1xTRxjKPHRe4gwQqjGcFTz1MuU=
github.com/pingcap/pd v2.1.0+incompatible/go.mod h1:nD3+EoYes4+aNNODO99ES59V83MZSI+dFbhyr667a0E=
Expand Down
2 changes: 1 addition & 1 deletion infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (s *testSuite) TestCharacterSetCollations(c *C) {
// The is_default column is not important
// but the id's are used by client libraries and must be stable
tk.MustQuery("SELECT character_set_name, id, sortlen FROM information_schema.collations ORDER BY collation_name").Check(
testkit.Rows("armscii8 64 1", "armscii8 32 1", "ascii 65 1", "ascii 11 1", "big5 84 1", "big5 1 1", "binary 63 1", "cp1250 66 1", "cp1250 44 1", "cp1250 34 1", "cp1250 26 1", "cp1250 99 1", "cp1251 50 1", "cp1251 14 1", "cp1251 51 1", "cp1251 52 1", "cp1251 23 1", "cp1256 67 1", "cp1256 57 1", "cp1257 58 1", "cp1257 59 1", "cp1257 29 1", "cp850 80 1", "cp850 4 1", "cp852 81 1", "cp852 40 1", "cp866 68 1", "cp866 36 1", "cp932 96 1", "cp932 95 1", "dec8 69 1", "dec8 3 1", "eucjpms 98 1", "eucjpms 97 1", "euckr 85 1", "euckr 19 1", "gb2312 86 1", "gb2312 24 1", "gbk 87 1", "gbk 28 1", "geostd8 93 1", "geostd8 92 1", "greek 70 1", "greek 25 1", "hebrew 71 1", "hebrew 16 1", "hp8 72 1", "hp8 6 1", "keybcs2 73 1", "keybcs2 37 1", "koi8r 74 1", "koi8r 7 1", "koi8u 75 1", "koi8u 22 1", "latin1 47 1", "latin1 15 1", "latin1 48 1", "latin1 49 1", "latin1 5 1", "latin1 31 1", "latin1 94 1", "latin1 8 1", "latin2 77 1", "latin2 27 1", "latin2 2 1", "latin2 9 1", "latin2 21 1", "latin5 78 1", "latin5 30 1", "latin7 79 1", "latin7 20 1", "latin7 41 1", "latin7 42 1", "macce 43 1", "macce 38 1", "macroman 53 1", "macroman 39 1", "sjis 88 1", "sjis 13 1", "swe7 82 1", "swe7 10 1", "tis620 89 1", "tis620 18 1", "ucs2 90 1", "ucs2 149 1", "ucs2 138 1", "ucs2 139 1", "ucs2 145 1", "ucs2 134 1", "ucs2 35 1", "ucs2 159 1", "ucs2 148 1", "ucs2 146 1", "ucs2 129 1", "ucs2 130 1", "ucs2 140 1", "ucs2 144 1", "ucs2 133 1", "ucs2 143 1", "ucs2 131 1", "ucs2 147 1", "ucs2 141 1", "ucs2 132 1", "ucs2 142 1", "ucs2 135 1", "ucs2 136 1", "ucs2 137 1", "ucs2 150 1", "ucs2 128 1", "ucs2 151 1", "ujis 91 1", "ujis 12 1", "utf16 55 1", "utf16 122 1", "utf16 111 1", "utf16 112 1", "utf16 118 1", "utf16 107 1", "utf16 54 1", "utf16 121 1", "utf16 119 1", "utf16 102 1", "utf16 103 1", "utf16 113 1", "utf16 117 1", "utf16 106 1", "utf16 116 1", "utf16 104 1", "utf16 120 1", "utf16 114 1", "utf16 105 1", "utf16 115 1", "utf16 108 1", "utf16 109 1", "utf16 110 1", "utf16 123 1", "utf16 101 1", "utf16 124 1", "utf16le 62 1", "utf16le 56 1", "utf32 61 1", "utf32 181 1", "utf32 170 1", "utf32 171 1", "utf32 177 1", "utf32 166 1", "utf32 60 1", "utf32 180 1", "utf32 178 1", "utf32 161 1", "utf32 162 1", "utf32 172 1", "utf32 176 1", "utf32 165 1", "utf32 175 1", "utf32 163 1", "utf32 179 1", "utf32 173 1", "utf32 164 1", "utf32 174 1", "utf32 167 1", "utf32 168 1", "utf32 169 1", "utf32 182 1", "utf32 160 1", "utf32 183 1", "utf8 83 1", "utf8 213 1", "utf8 202 1", "utf8 203 1", "utf8 209 1", "utf8 198 1", "utf8 33 1", "utf8 223 1", "utf8 212 1", "utf8 210 1", "utf8 193 1", "utf8 194 1", "utf8 204 1", "utf8 208 1", "utf8 197 1", "utf8 207 1", "utf8 195 1", "utf8 211 1", "utf8 205 1", "utf8 196 1", "utf8 206 1", "utf8 199 1", "utf8 200 1", "utf8 201 1", "utf8 214 1", "utf8 192 1", "utf8 215 1", "utf8mb4 46 1", "utf8mb4 245 1", "utf8mb4 234 1", "utf8mb4 235 1", "utf8mb4 241 1", "utf8mb4 230 1", "utf8mb4 45 1", "utf8mb4 244 1", "utf8mb4 242 1", "utf8mb4 225 1", "utf8mb4 226 1", "utf8mb4 236 1", "utf8mb4 240 1", "utf8mb4 229 1", "utf8mb4 239 1", "utf8mb4 227 1", "utf8mb4 243 1", "utf8mb4 237 1", "utf8mb4 228 1", "utf8mb4 238 1", "utf8mb4 231 1", "utf8mb4 232 1", "utf8mb4 233 1", "utf8mb4 246 1", "utf8mb4 224 1", "utf8mb4 247 1"))
testkit.Rows("armscii8 64 1", "armscii8 32 1", "ascii 65 1", "ascii 11 1", "big5 84 1", "big5 1 1", "binary 63 1", "cp1250 66 1", "cp1250 44 1", "cp1250 34 1", "cp1250 26 1", "cp1250 99 1", "cp1251 50 1", "cp1251 14 1", "cp1251 51 1", "cp1251 52 1", "cp1251 23 1", "cp1256 67 1", "cp1256 57 1", "cp1257 58 1", "cp1257 59 1", "cp1257 29 1", "cp850 80 1", "cp850 4 1", "cp852 81 1", "cp852 40 1", "cp866 68 1", "cp866 36 1", "cp932 96 1", "cp932 95 1", "dec8 69 1", "dec8 3 1", "eucjpms 98 1", "eucjpms 97 1", "euckr 85 1", "euckr 19 1", "gb2312 86 1", "gb2312 24 1", "gbk 87 1", "gbk 28 1", "geostd8 93 1", "geostd8 92 1", "greek 70 1", "greek 25 1", "hebrew 71 1", "hebrew 16 1", "hp8 72 1", "hp8 6 1", "keybcs2 73 1", "keybcs2 37 1", "koi8r 74 1", "koi8r 7 1", "koi8u 75 1", "koi8u 22 1", "latin1 47 1", "latin1 15 1", "latin1 48 1", "latin1 49 1", "latin1 5 1", "latin1 31 1", "latin1 94 1", "latin1 8 1", "latin2 77 1", "latin2 27 1", "latin2 2 1", "latin2 9 1", "latin2 21 1", "latin5 78 1", "latin5 30 1", "latin7 79 1", "latin7 20 1", "latin7 41 1", "latin7 42 1", "macce 43 1", "macce 38 1", "macroman 53 1", "macroman 39 1", "sjis 88 1", "sjis 13 1", "swe7 82 1", "swe7 10 1", "tis620 89 1", "tis620 18 1", "ucs2 90 1", "ucs2 149 1", "ucs2 138 1", "ucs2 139 1", "ucs2 145 1", "ucs2 134 1", "ucs2 35 1", "ucs2 159 1", "ucs2 148 1", "ucs2 146 1", "ucs2 129 1", "ucs2 130 1", "ucs2 140 1", "ucs2 144 1", "ucs2 133 1", "ucs2 143 1", "ucs2 131 1", "ucs2 147 1", "ucs2 141 1", "ucs2 132 1", "ucs2 142 1", "ucs2 135 1", "ucs2 136 1", "ucs2 137 1", "ucs2 150 1", "ucs2 128 1", "ucs2 151 1", "ujis 91 1", "ujis 12 1", "utf16 55 1", "utf16 122 1", "utf16 111 1", "utf16 112 1", "utf16 118 1", "utf16 107 1", "utf16 54 1", "utf16 121 1", "utf16 119 1", "utf16 102 1", "utf16 103 1", "utf16 113 1", "utf16 117 1", "utf16 106 1", "utf16 116 1", "utf16 104 1", "utf16 120 1", "utf16 114 1", "utf16 105 1", "utf16 115 1", "utf16 108 1", "utf16 109 1", "utf16 110 1", "utf16 123 1", "utf16 101 1", "utf16 124 1", "utf16le 62 1", "utf16le 56 1", "utf32 61 1", "utf32 181 1", "utf32 170 1", "utf32 171 1", "utf32 177 1", "utf32 166 1", "utf32 60 1", "utf32 180 1", "utf32 178 1", "utf32 161 1", "utf32 162 1", "utf32 172 1", "utf32 176 1", "utf32 165 1", "utf32 175 1", "utf32 163 1", "utf32 179 1", "utf32 173 1", "utf32 164 1", "utf32 174 1", "utf32 167 1", "utf32 168 1", "utf32 169 1", "utf32 182 1", "utf32 160 1", "utf32 183 1", "utf8 83 1", "utf8 213 1", "utf8 202 1", "utf8 203 1", "utf8 209 1", "utf8 198 1", "utf8 33 1", "utf8 223 1", "utf8 212 1", "utf8 210 1", "utf8 193 1", "utf8 194 1", "utf8 204 1", "utf8 208 1", "utf8 197 1", "utf8 207 1", "utf8 195 1", "utf8 211 1", "utf8 205 1", "utf8 196 1", "utf8 206 1", "utf8 199 1", "utf8 200 1", "utf8 201 1", "utf8 214 1", "utf8 192 1", "utf8 215 1", "utf8mb4 255 1", "utf8mb4 46 1", "utf8mb4 245 1", "utf8mb4 234 1", "utf8mb4 235 1", "utf8mb4 241 1", "utf8mb4 230 1", "utf8mb4 45 1", "utf8mb4 244 1", "utf8mb4 242 1", "utf8mb4 225 1", "utf8mb4 226 1", "utf8mb4 236 1", "utf8mb4 240 1", "utf8mb4 229 1", "utf8mb4 239 1", "utf8mb4 227 1", "utf8mb4 243 1", "utf8mb4 237 1", "utf8mb4 228 1", "utf8mb4 238 1", "utf8mb4 231 1", "utf8mb4 232 1", "utf8mb4 233 1", "utf8mb4 246 1", "utf8mb4 224 1", "utf8mb4 247 1"))

}

Expand Down
23 changes: 20 additions & 3 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,11 @@ type PartitionType int

// Partition types.
const (
PartitionTypeRange PartitionType = 1
PartitionTypeHash PartitionType = 2
PartitionTypeList PartitionType = 3
PartitionTypeRange PartitionType = 1
PartitionTypeHash = 2
PartitionTypeList = 3
PartitionTypeKey = 4
PartitionTypeSystemTime = 5
)

func (p PartitionType) String() string {
Expand All @@ -297,6 +299,10 @@ func (p PartitionType) String() string {
return "HASH"
case PartitionTypeList:
return "LIST"
case PartitionTypeKey:
return "KEY"
case PartitionTypeSystemTime:
return "SYSTEM_TIME"
default:
return ""
}
Expand All @@ -315,6 +321,17 @@ type PartitionInfo struct {
Enable bool `json:"enable"`

Definitions []PartitionDefinition `json:"definitions"`
Num uint64 `json:"num"`
}

// GetNameByID gets the partition name by ID.
func (pi *PartitionInfo) GetNameByID(id int64) string {
for _, def := range pi.Definitions {
if id == def.ID {
return def.Name.L
}
}
return ""
}

// PartitionDefinition defines a single partition.
Expand Down
26 changes: 21 additions & 5 deletions mysql/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,27 @@ const (
ErrInvalidJSONContainsPathType = 3150
ErrJSONUsedAsKey = 3152

// MariaDB errors.
ErrOnlyOneDefaultPartionAllowed = 4030
ErrWrongPartitionTypeExpectedSystemTime = 4113
ErrSystemVersioningWrongPartitions = 4128

// TiDB self-defined errors.
ErrMemExceedThreshold = 8001
ErrForUpdateCantRetry = 8002
ErrAdminCheckTable = 8003
ErrMemExceedThreshold = 8001
ErrForUpdateCantRetry = 8002
ErrAdminCheckTable = 8003
ErrTxnTooLarge = 8004
ErrWriteConflictInTiDB = 8005
ErrInvalidPluginID = 8101
ErrInvalidPluginManifest = 8102
ErrInvalidPluginName = 8103
ErrInvalidPluginVersion = 8104
ErrDuplicatePlugin = 8105
ErrInvalidPluginSysVarName = 8106
ErrRequireVersionCheckFail = 8107
ErrUnsupportedReloadPlugin = 8018
ErrUnsupportedReloadPluginVar = 8019
ErrTableLocked = 8020

// TiKV/PD errors.
ErrPDServerTimeout = 9001
Expand All @@ -905,6 +922,5 @@ const (
ErrResolveLockTimeout = 9004
ErrRegionUnavailable = 9005
ErrGCTooEarly = 9006

ErrTxnTooLarge = 9500
ErrWriteConflict = 9007
)
Loading

0 comments on commit 33725dd

Please sign in to comment.