Skip to content

Commit b90c5fc

Browse files
committed
*: support parsing all PARTITION BY syntax
1 parent f244897 commit b90c5fc

File tree

10 files changed

+7912
-6980
lines changed

10 files changed

+7912
-6980
lines changed

ast/ddl.go

Lines changed: 505 additions & 51 deletions
Large diffs are not rendered by default.

ast/expressions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (tc *testExpressionsSuite) TestMaxValueExprRestore(c *C) {
330330
{"maxvalue", "MAXVALUE"},
331331
}
332332
extractNodeFunc := func(node Node) Node {
333-
return node.(*AlterTableStmt).Specs[0].PartDefinitions[0].LessThan[0]
333+
return node.(*AlterTableStmt).Specs[0].PartDefinitions[0].Clause.(*PartitionDefinitionClauseLessThan).Exprs[0]
334334
}
335335
RunNodeRestoreTest(c, testCases, "alter table posts add partition ( partition p1 values less than %s)", extractNodeFunc)
336336
}

misc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ var tokenMap = map[string]int{
234234
"DELETE": deleteKwd,
235235
"DESC": desc,
236236
"DESCRIBE": describe,
237+
"DIRECTORY": directory,
237238
"DISABLE": disable,
238239
"DISTINCT": distinct,
239240
"DISTINCTROW": distinct,
@@ -289,6 +290,7 @@ var tokenMap = map[string]int{
289290
"HASH": hash,
290291
"HAVING": having,
291292
"HIGH_PRIORITY": highPriority,
293+
"HISTORY": history,
292294
"HOUR": hour,
293295
"HOUR_MICROSECOND": hourMicrosecond,
294296
"HOUR_MINUTE": hourMinute,
@@ -338,6 +340,7 @@ var tokenMap = map[string]int{
338340
"LIMIT": limit,
339341
"LINES": lines,
340342
"LINEAR": linear,
343+
"LIST": list,
341344
"LOAD": load,
342345
"LOCAL": local,
343346
"LOCALTIME": localTime,
@@ -380,6 +383,7 @@ var tokenMap = map[string]int{
380383
"NO_WRITE_TO_BINLOG": noWriteToBinLog,
381384
"NODE_ID": nodeID,
382385
"NODE_STATE": nodeState,
386+
"NODEGROUP": nodegroup,
383387
"NONE": none,
384388
"NOT": not,
385389
"NOW": now,
@@ -488,6 +492,7 @@ var tokenMap = map[string]int{
488492
"STATUS": status,
489493
"SWAPS": swaps,
490494
"SWITCHES": switchesSym,
495+
"SYSTEM_TIME": systemTime,
491496
"OPEN": open,
492497
"STD": stddevPop,
493498
"STDDEV": stddevPop,

model/model.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,11 @@ type PartitionType int
452452

453453
// Partition types.
454454
const (
455-
PartitionTypeRange PartitionType = 1
456-
PartitionTypeHash PartitionType = 2
457-
PartitionTypeList PartitionType = 3
455+
PartitionTypeRange PartitionType = 1
456+
PartitionTypeHash = 2
457+
PartitionTypeList = 3
458+
PartitionTypeKey = 4
459+
PartitionTypeSystemTime = 5
458460
)
459461

460462
func (p PartitionType) String() string {
@@ -465,6 +467,10 @@ func (p PartitionType) String() string {
465467
return "HASH"
466468
case PartitionTypeList:
467469
return "LIST"
470+
case PartitionTypeKey:
471+
return "KEY"
472+
case PartitionTypeSystemTime:
473+
return "SYSTEM_TIME"
468474
default:
469475
return ""
470476
}

mysql/errcode.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ const (
921921
ErrWindowExplainJson = 3598
922922
ErrWindowFunctionIgnoresFrame = 3599
923923

924+
// MariaDB errors.
925+
ErrOnlyOneDefaultPartionAllowed = 4030
926+
ErrWrongPartitionTypeExpectedSystemTime = 4113
927+
ErrSystemVersioningWrongPartitions = 4128
928+
924929
// TiDB self-defined errors.
925930
ErrMemExceedThreshold = 8001
926931
ErrForUpdateCantRetry = 8002

mysql/errname.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,11 @@ var MySQLErrName = map[uint16]string{
917917
ErrRoleNotGranted: "%s is is not granted to %s",
918918
ErrMaxExecTimeExceeded: "Query execution was interrupted, max_execution_time exceeded.",
919919

920+
// MariaDB errors.
921+
ErrOnlyOneDefaultPartionAllowed: "Only one DEFAULT partition allowed",
922+
ErrWrongPartitionTypeExpectedSystemTime: "Wrong partitioning type, expected type: `SYSTEM_TIME`",
923+
ErrSystemVersioningWrongPartitions: "Wrong Partitions: must have at least one HISTORY and exactly one last CURRENT",
924+
920925
// TiDB errors.
921926
ErrMemExceedThreshold: "%s holds %dB memory, exceeds threshold %dB.%s",
922927
ErrForUpdateCantRetry: "[%d] can not retry select for update statement",

0 commit comments

Comments
 (0)