Skip to content

Commit

Permalink
parser: parse more PARTITION option (pingcap#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and coocood committed Nov 30, 2016
1 parent 0b828d4 commit 1bca024
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
4 changes: 4 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ var tokenMap = map[string]int{
"LEADING": leading,
"LEFT": left,
"LENGTH": length,
"LESS": less,
"LEVEL": level,
"LIKE": like,
"LIMIT": limit,
Expand All @@ -296,6 +297,7 @@ var tokenMap = map[string]int{
"LOW_PRIORITY": lowPriority,
"LTRIM": ltrim,
"MAX": max,
"MAXVALUE": maxValue,
"MAX_ROWS": maxRows,
"MICROSECOND": microsecond,
"MIN": min,
Expand Down Expand Up @@ -329,6 +331,7 @@ var tokenMap = map[string]int{
"PROCESSLIST": processlist,
"QUARTER": quarter,
"QUICK": quick,
"RANGE": rangeKwd,
"RAND": rand,
"READ": read,
"REDUNDANT": redundant,
Expand Down Expand Up @@ -375,6 +378,7 @@ var tokenMap = map[string]int{
"TABLE": tableKwd,
"TABLES": tables,
"TERMINATED": terminated,
"THAN": than,
"THEN": then,
"TO": to,
"TRAILING": trailing,
Expand Down
58 changes: 45 additions & 13 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ import (
longblobType "LONGBLOB"
longtextType "LONGTEXT"
lowPriority "LOW_PRIORITY"
maxValue "MAXVALUE"
mediumblobType "MEDIUMBLOB"
mediumIntType "MEDIUMINT"
mediumtextType "MEDIUMTEXT"
Expand All @@ -163,6 +164,7 @@ import (
precisionType "PRECISION"
primary "PRIMARY"
procedure "PROCEDURE"
rangeKwd "RANGE"
read "READ"
realType "REAL"
references "REFERENCES"
Expand Down Expand Up @@ -334,6 +336,7 @@ import (
indexes "INDEXES"
keyBlockSize "KEY_BLOCK_SIZE"
local "LOCAL"
less "LESS"
level "LEVEL"
mode "MODE"
modify "MODIFY"
Expand Down Expand Up @@ -370,6 +373,7 @@ import (
global "GLOBAL"
tables "TABLES"
textType "TEXT"
than "THAN"
timeType "TIME"
timestampType "TIMESTAMP"
transaction "TRANSACTION"
Expand Down Expand Up @@ -542,7 +546,11 @@ import (
OrderByOptional "Optional ORDER BY clause optional"
ByList "BY list"
QuickOptional "QUICK or empty"
PartitionDefinition "Partition definition"
PartitionDefinitionList "Partition definition list"
PartitionDefinitionListOpt "Partition definition list option"
PartitionOpt "Partition option"
PartitionNumOpt "PARTITION NUM option"
PasswordOpt "Password option"
ColumnPosition "Column position [First|After ColumnName]"
PreparedStmt "PreparedStmt"
Expand Down Expand Up @@ -1439,7 +1447,31 @@ DefaultKwdOpt:

PartitionOpt:
{}
| "PARTITION" "BY" "HASH" '(' Expression ')' "PARTITIONS" NUM
| "PARTITION" "BY" "HASH" '(' Expression ')' PartitionNumOpt PartitionDefinitionListOpt
{}
| "PARTITION" "BY" "RANGE" '(' Expression ')' PartitionNumOpt PartitionDefinitionListOpt
{}

PartitionNumOpt:
{}
| "PARTITIONS" NUM
{}

PartitionDefinitionListOpt:
{}
| '(' PartitionDefinitionList ')'
{}

PartitionDefinitionList:
PartitionDefinition
{}
| PartitionDefinition ',' PartitionDefinitionList
{}

PartitionDefinition:
"PARTITION" Identifier "VALUES" "LESS" "THAN" ExpressionList "ENGINE" eq Identifier
{}
| "PARTITION" Identifier "VALUES" "LESS" "THAN" "MAXVALUE" "ENGINE" eq Identifier
{}

/******************************************************************
Expand Down Expand Up @@ -1999,15 +2031,15 @@ Identifier | ReservedKeyword

UnReservedKeyword:
"ACTION" | "ASCII" | "AUTO_INCREMENT" | "AFTER" | "AT" | "AVG" | "BEGIN" | "BIT" | "BOOL" | "BOOLEAN" | "BTREE" | "CHARSET"
| "COLUMNS" | "COMMIT" | "COMPACT" | "COMPRESSED" | "CONSISTENT" | "DATA" | "DATE" | "DATETIME" | "DEALLOCATE" | "DO"
| "DYNAMIC"| "END" | "ENGINE" | "ENGINES" | "ESCAPE" | "EXECUTE" | "FIELDS" | "FIRST" | "FIXED" | "FULL" |"GLOBAL"
| "HASH" | "LOCAL" | "NAMES" | "OFFSET" | "PASSWORD" %prec lowerThanEq | "PREPARE" | "QUICK" | "REDUNDANT" | "ROLLBACK"
| "SESSION" | "SIGNED" | "SNAPSHOT" | "START" | "STATUS" | "TABLES" | "TEXT" | "TIME" | "TIMESTAMP" | "TRANSACTION"
| "TRUNCATE" | "UNKNOWN" | "VALUE" | "WARNINGS" | "YEAR" | "MODE" | "WEEK" | "ANY" | "SOME" | "USER" | "IDENTIFIED"
| "COLLATION" | "COMMENT" | "AVG_ROW_LENGTH" | "CONNECTION" | "CHECKSUM" | "COMPRESSION" | "KEY_BLOCK_SIZE" | "MAX_ROWS"
| "MIN_ROWS" | "NATIONAL" | "ROW" | "ROW_FORMAT" | "QUARTER" | "GRANTS" | "TRIGGERS" | "DELAY_KEY_WRITE" | "ISOLATION"
| "REPEATABLE" | "COMMITTED" | "UNCOMMITTED" | "ONLY" | "SERIALIZABLE" | "LEVEL" | "VARIABLES" | "SQL_CACHE" | "INDEXES" | "PROCESSLIST"
| "SQL_NO_CACHE" | "DISABLE" | "ENABLE" | "REVERSE" | "SPACE" | "PRIVILEGES" | "NO" | "BINLOG" | "FUNCTION" | "VIEW" | "MODIFY" | "EVENTS" | "PARTITIONS"
| "COLUMNS" | "COMMIT" | "COMPACT" | "COMPRESSED" | "CONSISTENT" | "DATA" | "DATE" | "DATETIME" | "DEALLOCATE" | "DO"
| "DYNAMIC"| "END" | "ENGINE" | "ENGINES" | "ESCAPE" | "EXECUTE" | "FIELDS" | "FIRST" | "FIXED" | "FULL" |"GLOBAL"
| "HASH" | "LESS" | "LOCAL" | "NAMES" | "OFFSET" | "PASSWORD" %prec lowerThanEq | "PREPARE" | "QUICK" | "REDUNDANT"
| "ROLLBACK" | "SESSION" | "SIGNED" | "SNAPSHOT" | "START" | "STATUS" | "TABLES" | "TEXT" | "THAN" | "TIME" | "TIMESTAMP"
| "TRANSACTION" | "TRUNCATE" | "UNKNOWN" | "VALUE" | "WARNINGS" | "YEAR" | "MODE" | "WEEK" | "ANY" | "SOME" | "USER" | "IDENTIFIED"
| "COLLATION" | "COMMENT" | "AVG_ROW_LENGTH" | "CONNECTION" | "CHECKSUM" | "COMPRESSION" | "KEY_BLOCK_SIZE" | "MAX_ROWS"
| "MIN_ROWS" | "NATIONAL" | "ROW" | "ROW_FORMAT" | "QUARTER" | "GRANTS" | "TRIGGERS" | "DELAY_KEY_WRITE" | "ISOLATION"
| "REPEATABLE" | "COMMITTED" | "UNCOMMITTED" | "ONLY" | "SERIALIZABLE" | "LEVEL" | "VARIABLES" | "SQL_CACHE" | "INDEXES" | "PROCESSLIST"
| "SQL_NO_CACHE" | "DISABLE" | "ENABLE" | "REVERSE" | "SPACE" | "PRIVILEGES" | "NO" | "BINLOG" | "FUNCTION" | "VIEW" | "MODIFY" | "EVENTS" | "PARTITIONS"

ReservedKeyword:
"ADD" | "ALL" | "ALTER" | "ANALYZE" | "AND" | "AS" | "ASC" | "BETWEEN" | "BIGINT"
Expand All @@ -2020,10 +2052,10 @@ ReservedKeyword:
| "FULLTEXT" | "GRANT" | "GROUP" | "HAVING" | "HOUR_MICROSECOND" | "HOUR_MINUTE"
| "HOUR_SECOND" | "IF" | "IGNORE" | "IN" | "INDEX" | "INFILE" | "INNER" | "INSERT" | "INT" | "INTO" | "INTEGER"
| "INTERVAL" | "IS" | "JOIN" | "KEY" | "KEYS" | "LEADING" | "LEFT" | "LIKE" | "LIMIT" | "LINES" | "LOAD"
| "LOCALTIME" | "LOCALTIMESTAMP" | "LOCK" | "LONGBLOB" | "LONGTEXT" | "MEDIUMBLOB" | "MEDIUMINT" | "MEDIUMTEXT"
| "LOCALTIME" | "LOCALTIMESTAMP" | "LOCK" | "LONGBLOB" | "LONGTEXT" | "MAXVALUE" | "MEDIUMBLOB" | "MEDIUMINT" | "MEDIUMTEXT"
| "MINUTE_MICROSECOND" | "MINUTE_SECOND" | "MOD" | "NOT" | "NO_WRITE_TO_BINLOG" | "NULL" | "NUMERIC"
| "ON" | "OPTION" | "OR" | "ORDER" | "OUTER" | "PARTITION" | "PRECISION" | "PRIMARY" | "PROCEDURE" | "READ" | "REAL"
| "REFERENCES" | "REGEXP" | "REPEAT" | "REPLACE" | "RESTRICT" | "RIGHT" | "RLIKE"
| "ON" | "OPTION" | "OR" | "ORDER" | "OUTER" | "PARTITION" | "PRECISION" | "PRIMARY" | "PROCEDURE" | "RANGE" | "READ"
| "REAL" | "REFERENCES" | "REGEXP" | "REPEAT" | "REPLACE" | "RESTRICT" | "RIGHT" | "RLIKE"
| "SCHEMA" | "SCHEMAS" | "SECOND_MICROSECOND" | "SELECT" | "SET" | "SHOW" | "SMALLINT"
| "STARTING" | "TABLE" | "TERMINATED" | "THEN" | "TINYBLOB" | "TINYINT" | "TINYTEXT" | "TO"
| "TRAILING" | "TRUE" | "UNION" | "UNIQUE" | "UNLOCK" | "UNSIGNED"
Expand Down
7 changes: 4 additions & 3 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (s *testParserSuite) TestSimple(c *C) {
"fulltext", "grant", "group", "having", "hour_microsecond", "hour_minute",
"hour_second", "if", "ignore", "in", "index", "infile", "inner", "insert", "int", "into", "integer",
"interval", "is", "join", "key", "keys", "leading", "left", "like", "limit", "lines", "load",
"localtime", "localtimestamp", "lock", "longblob", "longtext", "mediumblob", "mediumint", "mediumtext",
"localtime", "localtimestamp", "lock", "longblob", "longtext", "mediumblob", "maxvalue", "mediumint", "mediumtext",
"minute_microsecond", "minute_second", "mod", "not", "no_write_to_binlog", "null", "numeric",
"on", "option", "or", "order", "outer", "partition", "precision", "primary", "procedure", "read", "real",
"on", "option", "or", "order", "outer", "partition", "precision", "primary", "procedure", "range", "read", "real",
"references", "regexp", "repeat", "replace", "restrict", "right", "rlike",
"schema", "schemas", "second_microsecond", "select", "set", "show", "smallint",
"starting", "table", "terminated", "then", "tinyblob", "tinyint", "tinytext", "to",
Expand Down Expand Up @@ -88,7 +88,7 @@ func (s *testParserSuite) TestSimple(c *C) {
"curtime", "variables", "dayname", "version", "btree", "hash", "row_format", "dynamic", "fixed", "compressed",
"compact", "redundant", "sql_no_cache sql_no_cache", "sql_cache sql_cache", "action", "round",
"enable", "disable", "reverse", "space", "privileges", "get_lock", "release_lock", "sleep", "no", "greatest",
"binlog", "hex", "unhex", "function", "indexes", "from_unixtime", "processlist", "events",
"binlog", "hex", "unhex", "function", "indexes", "from_unixtime", "processlist", "events", "less", "than",
}
for _, kw := range unreservedKws {
src := fmt.Sprintf("SELECT %s FROM tbl;", kw)
Expand Down Expand Up @@ -848,6 +848,7 @@ func (s *testParserSuite) TestDDL(c *C) {
{"create table t (c int) STATS_PERSISTENT = 1", true},
// Partition option
{"create table t (c int) PARTITION BY HASH (c) PARTITIONS 32;", true},
{"create table t (c int) PARTITION BY RANGE (Year(VDate)) (PARTITION p1980 VALUES LESS THAN (1980) ENGINE = MyISAM, PARTITION p1990 VALUES LESS THAN (1990) ENGINE = MyISAM, PARTITION pothers VALUES LESS THAN MAXVALUE ENGINE = MyISAM)", true},
// For check clause
{"create table t (c1 bool, c2 bool, check (c1 in (0, 1)), check (c2 in (0, 1)))", true},
{"CREATE TABLE Customer (SD integer CHECK (SD > 0), First_Name varchar(30));", true},
Expand Down

0 comments on commit 1bca024

Please sign in to comment.