Skip to content

Commit

Permalink
*: avoid using TypeDecimal (pingcap#2619)
Browse files Browse the repository at this point in the history
TypeDecimal is misleading, it is not used as Decimal type, it's an unspecified type.
  • Loading branch information
coocood authored Feb 10, 2017
1 parent be2812f commit 8ba5d9e
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 18 deletions.
8 changes: 1 addition & 7 deletions mysql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ const (
)

// TypeUnspecified is an uninitialized type. TypeDecimal is not used in MySQL.
var TypeUnspecified = TypeDecimal

// IsUninitializedType check if a type code is uninitialized.
// TypeDecimal is the old type code for decimal and not be used in the new mysql version.
func IsUninitializedType(tp byte) bool {
return tp == TypeDecimal
}
const TypeUnspecified = TypeDecimal

// Flag informations.
const (
Expand Down
4 changes: 2 additions & 2 deletions mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func GetDefaultFieldLength(tp byte) int {
return 11
case TypeLonglong:
return 21
case TypeDecimal, TypeNewDecimal:
case TypeNewDecimal:
// See https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
return 10
case TypeBit, TypeBlob:
Expand All @@ -44,7 +44,7 @@ func GetDefaultFieldLength(tp byte) int {
// GetDefaultDecimal returns the default decimal length for column.
func GetDefaultDecimal(tp byte) int {
switch tp {
case TypeDecimal, TypeNewDecimal:
case TypeNewDecimal:
// See https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
return 0
default:
Expand Down
2 changes: 1 addition & 1 deletion plan/aggregation_pruning.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (ap *aggPruner) rewriteExpr(exprs []expression.Expression, funcName string)
case mysql.TypeTiny, mysql.TypeShort, mysql.TypeInt24, mysql.TypeLong, mysql.TypeLonglong:
newExpr = expression.NewCastFunc(types.NewFieldType(mysql.TypeNewDecimal), expr, ap.ctx)
// Double and Decimal doesn't need to be cast.
case mysql.TypeDouble, mysql.TypeDecimal, mysql.TypeNewDecimal:
case mysql.TypeDouble, mysql.TypeNewDecimal:
newExpr = expr
// Float should be cast to double. And other non-numeric type should be cast to double too.
default:
Expand Down
2 changes: 1 addition & 1 deletion plan/expr_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (pc pbConverter) columnToPBExpr(column *expression.Column) *tipb.Expr {
return nil
}
switch column.GetType().Tp {
case mysql.TypeBit, mysql.TypeSet, mysql.TypeEnum, mysql.TypeGeometry, mysql.TypeDecimal:
case mysql.TypeBit, mysql.TypeSet, mysql.TypeEnum, mysql.TypeGeometry, mysql.TypeUnspecified:
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion server/conn_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy
pos += 8
continue

case mysql.TypeDecimal, mysql.TypeNewDecimal, mysql.TypeVarchar,
case mysql.TypeUnspecified, mysql.TypeNewDecimal, mysql.TypeVarchar,
mysql.TypeBit, mysql.TypeEnum, mysql.TypeSet, mysql.TypeTinyBlob,
mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob,
mysql.TypeVarString, mysql.TypeString, mysql.TypeGeometry,
Expand Down
4 changes: 2 additions & 2 deletions util/types/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ func (s *testTypeConvertSuite) TestStrToNum(c *C) {

func (s *testTypeConvertSuite) TestFieldTypeToStr(c *C) {
defer testleak.AfterTest(c)()
v := TypeToStr(mysql.TypeDecimal, "not binary")
c.Assert(v, Equals, type2Str[mysql.TypeDecimal])
v := TypeToStr(mysql.TypeUnspecified, "not binary")
c.Assert(v, Equals, type2Str[mysql.TypeUnspecified])
v = TypeToStr(mysql.TypeBlob, charset.CharsetBin)
c.Assert(v, Equals, "blob")
v = TypeToStr(mysql.TypeString, charset.CharsetBin)
Expand Down
2 changes: 1 addition & 1 deletion util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func (d *Datum) ConvertTo(sc *variable.StatementContext, target *FieldType) (Dat
return d.convertToMysqlDuration(sc, target)
case mysql.TypeBit:
return d.convertToMysqlBit(sc, target)
case mysql.TypeDecimal, mysql.TypeNewDecimal:
case mysql.TypeNewDecimal:
return d.convertToMysqlDecimal(sc, target)
case mysql.TypeYear:
return d.convertToMysqlYear(sc, target)
Expand Down
2 changes: 1 addition & 1 deletion util/types/etc.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var type2Str = map[byte]string{
mysql.TypeBlob: "text",
mysql.TypeDate: "date",
mysql.TypeDatetime: "datetime",
mysql.TypeDecimal: "decimal",
mysql.TypeDecimal: "unspecified",
mysql.TypeNewDecimal: "decimal",
mysql.TypeDouble: "double",
mysql.TypeEnum: "enum",
Expand Down
2 changes: 1 addition & 1 deletion util/types/etc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (s *testTypeEtcSuite) TestTypeToStr(c *C) {
testTypeToStr(c, mysql.TypeDate, "binary", "date")
testTypeToStr(c, mysql.TypeTimestamp, "binary", "timestamp")
testTypeToStr(c, mysql.TypeNewDecimal, "binary", "decimal")
testTypeToStr(c, mysql.TypeDecimal, "binary", "decimal")
testTypeToStr(c, mysql.TypeUnspecified, "binary", "unspecified")
testTypeToStr(c, 0xdd, "binary", "")
testTypeToStr(c, mysql.TypeBit, "binary", "bit")
testTypeToStr(c, mysql.TypeEnum, "binary", "enum")
Expand Down
2 changes: 1 addition & 1 deletion util/types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func DefaultTypeForValue(value interface{}, tp *FieldType) {
tp.Charset = charset.CharsetBin
tp.Collate = charset.CharsetBin
default:
tp.Tp = mysql.TypeDecimal
tp.Tp = mysql.TypeUnspecified
}
tp.Flen = UnspecifiedLength
tp.Decimal = UnspecifiedLength
Expand Down

0 comments on commit 8ba5d9e

Please sign in to comment.