Skip to content

Commit

Permalink
fix stylecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed Jan 17, 2019
1 parent 285c4a9 commit 66d8fd7
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@ 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 {
Expand All @@ -2320,7 +2320,7 @@ func (d *ddl) DropTable(ctx sessionctx.Context, ti ast.Ident, tableId int64) (er

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 @@ -68,7 +68,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 @@ -83,9 +83,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 @@ -98,7 +98,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 @@ -96,7 +96,8 @@ func (e *DDLExec) Next(ctx context.Context, req *chunk.RecordBatch) (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 @@ -443,19 +443,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 66d8fd7

Please sign in to comment.