Skip to content

Commit

Permalink
fix stylecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed Dec 23, 2018
1 parent ac61d95 commit 34aef39
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ type DDL interface {
CreateTable(ctx sessionctx.Context, stmt *ast.CreateTableStmt, withSelect bool) (int64, error)
CreateView(ctx sessionctx.Context, stmt *ast.CreateViewStmt) error
CreateTableWithLike(ctx sessionctx.Context, ident, referIdent ast.Ident, ifNotExists bool) (int64, error)
DropTable(ctx sessionctx.Context, tableIdent ast.Ident, tableId int64) (err error)
DropTable(ctx sessionctx.Context, tableIdent ast.Ident, tableID int64) (err error)
CreateIndex(ctx sessionctx.Context, tableIdent ast.Ident, unique bool, indexName model.CIStr,
columnNames []*ast.IndexColName, indexOption *ast.IndexOption) error
DropIndex(ctx sessionctx.Context, tableIdent ast.Ident, indexName model.CIStr) error
Expand Down
12 changes: 6 additions & 6 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2189,24 +2189,24 @@ func (d *ddl) RenameIndex(ctx sessionctx.Context, ident ast.Ident, spec *ast.Alt
}

// DropTable will proceed even if some table in the list does not exists.
func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableId int64) (err error) {
func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableID int64) (err error) {
is := d.GetInformationSchema(ctx)
schema, ok := is.SchemaByName(ti.Schema)
if !ok {
return infoschema.ErrDatabaseNotExists.GenWithStackByArgs(ti.Schema)
}

if tableId == 0 {
tb, err := is.TableByName(ti.Schema, ti.Name)
if err != nil {
if tableID == 0 {
tb, e := is.TableByName(ti.Schema, ti.Name)
if e != nil {
return errors.Trace(infoschema.ErrTableNotExists.GenWithStackByArgs(ti.Schema, ti.Name))
}
tableId = tb.Meta().ID
tableID = tb.Meta().ID
}

job := &model.Job{
SchemaID: schema.ID,
TableID: tableId,
TableID: tableID,
Type: model.ActionDropTable,
BinlogInfo: &model.HistoryInfo{},
}
Expand Down
8 changes: 4 additions & 4 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error)
// TODO: Add restrictions to this operation.
go splitTableRegion(d.store, tbInfo.ID)
}
ver, err := updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
if err != nil {
job.State = model.JobStateCancelled
return ver, err
Expand All @@ -82,9 +82,9 @@ func onCreateTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error)
}
}

func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error) {
func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error) {
tbInfo := &model.TableInfo{}
if err := job.DecodeArgs(tbInfo); err != nil {
if err = job.DecodeArgs(tbInfo); err != nil {
// Invalid arguments, cancel this job.
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
Expand All @@ -97,7 +97,7 @@ func onRevealTable(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error)
tbInfo.State = model.StatePublic
tbInfo.UpdateTS = t.StartTS
// Finish this job.
ver, err := updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
ver, err = updateVersionAndTableInfo(t, job, tbInfo, originalState != tbInfo.State)
if err != nil {
job.State = model.JobStateCancelled
return ver, err
Expand Down
3 changes: 2 additions & 1 deletion executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (e *DDLExec) Next(ctx context.Context, chk *chunk.Chunk) (err error) {
case *ast.CreateDatabaseStmt:
err = e.executeCreateDatabase(x)
case *ast.CreateTableStmt:
tableID, err := e.executeCreateTable(x)
var tableID int64
tableID, err = e.executeCreateTable(x)
if err != nil {
return errors.Trace(e.toErr(err))
}
Expand Down
24 changes: 12 additions & 12 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,19 @@ func (e *ShowExec) fetchShowIndex() error {
subPart = col.Length
}
e.appendRow([]interface{}{
tb.Meta().Name.O, // Table
nonUniq, // Non_unique
idx.Meta().Name.O, // Key_name
i + 1, // Seq_in_index
col.Name.O, // Column_name
"A", // Collation
0, // Cardinality
subPart, // Sub_part
nil, // Packed
"YES", // Null
tb.Meta().Name.O, // Table
nonUniq, // Non_unique
idx.Meta().Name.O, // Key_name
i + 1, // Seq_in_index
col.Name.O, // Column_name
"A", // Collation
0, // Cardinality
subPart, // Sub_part
nil, // Packed
"YES", // Null
idx.Meta().Tp.String(), // Index_type
"", // Comment
idx.Meta().Comment, // Index_comment
"", // Comment
idx.Meta().Comment, // Index_comment
})
}
}
Expand Down
5 changes: 4 additions & 1 deletion types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,18 @@ func NewFieldType(tp byte) *FieldType {
}
}

// Clone makes a deep copy of FieldType
func (ft *FieldType) Clone() *FieldType {
elems := make([]string, len(ft.Elems))
copy(elems, ft.Elems)
return &FieldType{
Tp: ft.Tp,
Flag: ft.Flag,
Flen: ft.Flen,
Decimal: ft.Decimal,
Charset: ft.Charset,
Collate: ft.Collate,
Elems: ft.Elems,
Elems: elems,
}
}

Expand Down
24 changes: 24 additions & 0 deletions types/field_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,27 @@ func (s *testFieldTypeSuite) TestAggregateEvalType(c *C) {
}
}
}

func (s *testFieldTypeSuite) TestClone(c *C) {
defer testleak.AfterTest(c)()

ft := NewFieldType(mysql.TypeDecimal)
c.Assert(ft.Equal(ft.Clone()), IsTrue)

ft = NewFieldType(mysql.TypeLong)
ft.Flen = 5
ft.Flag = mysql.UnsignedFlag | mysql.ZerofillFlag
c.Assert(ft.Equal(ft.Clone()), IsTrue)

ft = NewFieldType(mysql.TypeFloat)
ft.Flen = 7
ft.Decimal = 3
ft.Charset = charset.CharsetASCII
ft.Collate = charset.CharsetBin
ft.Elems = []string{"a", "b", "c"}
c.Assert(ft.Equal(ft.Clone()), IsTrue)

ftc := ft.Clone()
ftc.Elems = append(ftc.Elems, "d")
c.Assert(ft.Equal(ftc), IsFalse)
}

0 comments on commit 34aef39

Please sign in to comment.