From 4b60e7291558bfc22ad1a7b2ccb9d4a77684a0c5 Mon Sep 17 00:00:00 2001 From: bb7133 Date: Tue, 26 Mar 2019 10:48:39 +0800 Subject: [PATCH] address comments: move handling ColumnOptionCollate to TiDB side --- ast/ddl.go | 6 +++++- parser.go | 13 +------------ parser.y | 13 +------------ 3 files changed, 7 insertions(+), 25 deletions(-) diff --git a/ast/ddl.go b/ast/ddl.go index 164125ddf..3dc9a61cf 100755 --- a/ast/ddl.go +++ b/ast/ddl.go @@ -419,7 +419,11 @@ func (n *ColumnOption) Restore(ctx *RestoreCtx) error { return errors.Annotate(err, "An error occurred while splicing ColumnOption ReferenceDef") } case ColumnOptionCollate: - // Do nothing, we should never see a ColumnOptionCollate after parsing + if n.StrValue == "" { + return errors.New("Empty ColumnOption COLLATE") + } + ctx.WriteKeyWord("COLLATE ") + ctx.WritePlain(n.StrValue) default: return errors.New("An error occurred while splicing ColumnOption") } diff --git a/parser.go b/parser.go index cdc72fb25..192f69087 100644 --- a/parser.go +++ b/parser.go @@ -7738,18 +7738,7 @@ yynewstate: } case 80: { - def := &ast.ColumnDef{Name: yyS[yypt-2].item.(*ast.ColumnName), Tp: yyS[yypt-1].item.(*types.FieldType)} - opts := make([]*ast.ColumnOption, 0) - for _, opt := range yyS[yypt-0].item.([]*ast.ColumnOption) { - // ColumnOptionCollate is only used to set FieldType.Collate - if opt.Tp == ast.ColumnOptionCollate { - def.Tp.Collate = opt.StrValue - } else { - opts = append(opts, opt) - } - } - def.Options = opts - parser.yyVAL.item = def + parser.yyVAL.item = &ast.ColumnDef{Name: yyS[yypt-2].item.(*ast.ColumnName), Tp: yyS[yypt-1].item.(*types.FieldType), Options: yyS[yypt-0].item.([]*ast.ColumnOption)} } case 81: { diff --git a/parser.y b/parser.y index 3112adc99..81b1c056f 100644 --- a/parser.y +++ b/parser.y @@ -1481,18 +1481,7 @@ ColumnDefList: ColumnDef: ColumnName Type ColumnOptionListOpt { - def := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType)} - opts := make([]*ast.ColumnOption, 0) - for _, opt := range $3.([]*ast.ColumnOption) { - // ColumnOptionCollate is only used to set FieldType.Collate - if opt.Tp == ast.ColumnOptionCollate { - def.Tp.Collate = opt.StrValue - } else { - opts = append(opts, opt) - } - } - def.Options = opts - $$ = def + $$ = &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)} } ColumnName: