Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: 添加tidb列属性auto_random支持(#269) #270

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ build:
$(GOBUILD)

goyacc:
$(GOBUILD) -o bin/goyacc parser/goyacc/main.go
@$(GOBUILD) -o bin/goyacc parser/goyacc/main.go

parser: goyacc
bin/goyacc -o /dev/null parser/parser.y
bin/goyacc -o parser/parser.go parser/parser.y 2>&1 | egrep "(shift|reduce)/reduce" | awk '{print} END {if (NR > 0) {print "Find conflict in parser.y. Please check y.output for more information."; exit 1;}}'
rm -f y.output
@bin/goyacc -o parser/parser.go parser/parser.y 2>&1 | egrep "(shift|reduce)/reduce" | awk '{print} END {if (NR > 0) {print "Find conflict in parser.y. Please check y.output for more information."; exit 1;} else {print "SUCCESS!"}}'
@rm -f y.output

@if [ $(ARCH) = $(LINUX) ]; \
then \
Expand Down
20 changes: 18 additions & 2 deletions ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ const (
ColumnOptionCollate
ColumnOptionCheck
ColumnOptionColumnFormat
ColumnOptionStorage
ColumnOptionAutoRandom
)

var (
Expand All @@ -420,8 +422,9 @@ type ColumnOption struct {
// Stored is only for ColumnOptionGenerated, default is false.
Stored bool
// Refer is used for foreign key.
Refer *ReferenceDef
StrValue string
Refer *ReferenceDef
StrValue string
AutoRandomBitLength int
}

// Restore implements Node interface.
Expand Down Expand Up @@ -478,6 +481,14 @@ func (n *ColumnOption) Restore(ctx *RestoreCtx) error {
}
ctx.WriteKeyWord("COLLATE ")
ctx.WritePlain(n.StrValue)
case ColumnOptionStorage:
ctx.WriteKeyWord("STORAGE ")
ctx.WriteKeyWord(n.StrValue)
case ColumnOptionAutoRandom:
ctx.WriteKeyWord("AUTO_RANDOM")
if n.AutoRandomBitLength != types.UnspecifiedLength {
ctx.WritePlainf("(%d)", n.AutoRandomBitLength)
}
default:
return errors.New("An error occurred while splicing ColumnOption")
}
Expand Down Expand Up @@ -1353,6 +1364,7 @@ const (
TableOptionCharset
TableOptionCollate
TableOptionAutoIncrement
TableOptionAutoRandomBase
TableOptionComment
TableOptionAvgRowLength
TableOptionCheckSum
Expand Down Expand Up @@ -1433,6 +1445,10 @@ func (n *TableOption) Restore(ctx *RestoreCtx) error {
ctx.WriteKeyWord("AUTO_INCREMENT ")
ctx.WritePlain("= ")
ctx.WritePlainf("%d", n.UintValue)
case TableOptionAutoRandomBase:
ctx.WriteKeyWord("AUTO_RANDOM_BASE ")
ctx.WritePlain("= ")
ctx.WritePlainf("%d", n.UintValue)
case TableOptionComment:
ctx.WriteKeyWord("COMMENT ")
ctx.WritePlain("= ")
Expand Down
112 changes: 57 additions & 55 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,61 +133,63 @@ func init() {
}

var tokenMap = map[string]int{
"ACTION": action,
"ADD": add,
"ADDDATE": addDate,
"ADMIN": admin,
"AFTER": after,
"ALL": all,
"ALGORITHM": algorithm,
"ALTER": alter,
"ALWAYS": always,
"ANALYZE": analyze,
"AND": and,
"ANY": any,
"AS": as,
"ASC": asc,
"ASCII": ascii,
"AUTO_INCREMENT": autoIncrement,
"AVG": avg,
"AVG_ROW_LENGTH": avgRowLength,
"BEGIN": begin,
"BETWEEN": between,
"BIGINT": bigIntType,
"BINARY": binaryType,
"BINLOG": binlog,
"BIT": bitType,
"BIT_AND": bitAnd,
"BIT_OR": bitOr,
"BIT_XOR": bitXor,
"BLOB": blobType,
"BOOL": boolType,
"BOOLEAN": booleanType,
"BOTH": both,
"BTREE": btree,
"BUCKETS": buckets,
"BY": by,
"BYTE": byteType,
"CANCEL": cancel,
"CASCADE": cascade,
"CASCADED": cascaded,
"CASE": caseKwd,
"CAST": cast,
"CHANGE": change,
"CHAR": charType,
"CHARACTER": character,
"CHARSET": charsetKwd,
"CHECK": check,
"CHECKSUM": checksum,
"CLEANUP": cleanup,
"CLIENT": client,
"COALESCE": coalesce,
"COLLATE": collate,
"COLLATION": collation,
"COLUMN": column,
"COLUMNS": columns,
"COMMENT": comment,
"COMMIT": commit,
"ACTION": action,
"ADD": add,
"ADDDATE": addDate,
"ADMIN": admin,
"AFTER": after,
"ALL": all,
"ALGORITHM": algorithm,
"ALTER": alter,
"ALWAYS": always,
"ANALYZE": analyze,
"AND": and,
"ANY": any,
"AS": as,
"ASC": asc,
"ASCII": ascii,
"AUTO_INCREMENT": autoIncrement,
"AUTO_RANDOM": autoRandom,
"AUTO_RANDOM_BASE": autoRandomBase,
"AVG": avg,
"AVG_ROW_LENGTH": avgRowLength,
"BEGIN": begin,
"BETWEEN": between,
"BIGINT": bigIntType,
"BINARY": binaryType,
"BINLOG": binlog,
"BIT": bitType,
"BIT_AND": bitAnd,
"BIT_OR": bitOr,
"BIT_XOR": bitXor,
"BLOB": blobType,
"BOOL": boolType,
"BOOLEAN": booleanType,
"BOTH": both,
"BTREE": btree,
"BUCKETS": buckets,
"BY": by,
"BYTE": byteType,
"CANCEL": cancel,
"CASCADE": cascade,
"CASCADED": cascaded,
"CASE": caseKwd,
"CAST": cast,
"CHANGE": change,
"CHAR": charType,
"CHARACTER": character,
"CHARSET": charsetKwd,
"CHECK": check,
"CHECKSUM": checksum,
"CLEANUP": cleanup,
"CLIENT": client,
"COALESCE": coalesce,
"COLLATE": collate,
"COLLATION": collation,
"COLUMN": column,
"COLUMNS": columns,
"COMMENT": comment,
"COMMIT": commit,

"COMMITTED": committed,
"COMPACT": compact,
Expand Down
Loading