Skip to content

Commit

Permalink
proto: misc renames
Browse files Browse the repository at this point in the history
Float -> Float32
Double -> Float64
IsNumber -> IsIntegral

Also addressed some code review comments.
  • Loading branch information
sougou committed Oct 24, 2015
1 parent c5691e1 commit 94eb00f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 63 deletions.
33 changes: 18 additions & 15 deletions go/sqltypes/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import (
"github.com/youtube/vitess/go/vt/proto/query"
)

// This file provides wrappers and support
// functions for query.Type.

// These bit flags can be used to query on the
// common properties of types.
const (
IsNumber = int(query.Flag_ISNUMBER)
IsIntegral = int(query.Flag_ISINTEGRAL)
IsUnsigned = int(query.Flag_ISUNSIGNED)
IsFloat = int(query.Flag_ISFLOAT)
IsQuoted = int(query.Flag_ISQUOTED)
Expand All @@ -35,8 +38,8 @@ const (
Uint32 = query.Type_UINT32
Int64 = query.Type_INT64
Uint64 = query.Type_UINT64
Float = query.Type_FLOAT
Double = query.Type_DOUBLE
Float32 = query.Type_FLOAT32
Float64 = query.Type_FLOAT64
Timestamp = query.Type_TIMESTAMP
Date = query.Type_DATE
Time = query.Type_TIME
Expand All @@ -55,13 +58,13 @@ const (
Tuple = query.Type_TUPLE
)

// bit-shift the mysql flags by one byte so we
// can merge them with the mysql types.
// bit-shift the mysql flags by two byte so we
// can merge them with the mysql or vitess types.
const (
mysqlUnsigned = 32 << 8
mysqlBinary = 128 << 8
mysqlEnum = 256 << 8
mysqlSet = 2048 << 8
mysqlUnsigned = 32 << 16
mysqlBinary = 128 << 16
mysqlEnum = 256 << 16
mysqlSet = 2048 << 16

relevantFlags = mysqlUnsigned |
mysqlBinary |
Expand All @@ -75,8 +78,8 @@ var mysqlToType = map[int64]query.Type{
1: Int8,
2: Int16,
3: Int32,
4: Float,
5: Double,
4: Float32,
5: Float64,
6: Null,
7: Timestamp,
8: Int64,
Expand Down Expand Up @@ -116,8 +119,8 @@ var typeToMySQL = map[query.Type]struct {
Uint16: {typ: 2, flags: mysqlUnsigned},
Int32: {typ: 3},
Uint32: {typ: 3, flags: mysqlUnsigned},
Float: {typ: 4},
Double: {typ: 5},
Float32: {typ: 4},
Float64: {typ: 5},
Null: {typ: 6, flags: mysqlBinary},
Timestamp: {typ: 7},
Int64: {typ: 8},
Expand Down Expand Up @@ -147,7 +150,7 @@ func MySQLToType(mysqlType, flags int64) (query.Type, error) {
return Null, fmt.Errorf("Could not map: %d to a vitess type", mysqlType)
}

converted := (flags << 8) & relevantFlags
converted := (flags << 16) & relevantFlags
modified, ok := modifier[int64(result)|converted]
if ok {
return modified, nil
Expand All @@ -158,5 +161,5 @@ func MySQLToType(mysqlType, flags int64) (query.Type, error) {
// TypeToMySQL returns the equivalent mysql type and flag for a vitess type.
func TypeToMySQL(typ query.Type) (mysqlType, flags int64) {
val := typeToMySQL[typ]
return val.typ, val.flags >> 8
return val.typ, val.flags >> 16
}
26 changes: 13 additions & 13 deletions go/sqltypes/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,39 @@ func TestTypeValues(t *testing.T) {
expected: 0,
}, {
defined: Int8,
expected: 1 | IsNumber,
expected: 1 | IsIntegral,
}, {
defined: Uint8,
expected: 2 | IsNumber | IsUnsigned,
expected: 2 | IsIntegral | IsUnsigned,
}, {
defined: Int16,
expected: 3 | IsNumber,
expected: 3 | IsIntegral,
}, {
defined: Uint16,
expected: 4 | IsNumber | IsUnsigned,
expected: 4 | IsIntegral | IsUnsigned,
}, {
defined: Int24,
expected: 5 | IsNumber,
expected: 5 | IsIntegral,
}, {
defined: Uint24,
expected: 6 | IsNumber | IsUnsigned,
expected: 6 | IsIntegral | IsUnsigned,
}, {
defined: Int32,
expected: 7 | IsNumber,
expected: 7 | IsIntegral,
}, {
defined: Uint32,
expected: 8 | IsNumber | IsUnsigned,
expected: 8 | IsIntegral | IsUnsigned,
}, {
defined: Int64,
expected: 9 | IsNumber,
expected: 9 | IsIntegral,
}, {
defined: Uint64,
expected: 10 | IsNumber | IsUnsigned,
expected: 10 | IsIntegral | IsUnsigned,
}, {
defined: Float,
defined: Float32,
expected: 11 | IsFloat,
}, {
defined: Double,
defined: Float64,
expected: 12 | IsFloat,
}, {
defined: Timestamp,
Expand All @@ -67,7 +67,7 @@ func TestTypeValues(t *testing.T) {
expected: 16 | IsQuoted,
}, {
defined: Year,
expected: 17 | IsNumber | IsUnsigned,
expected: 17 | IsIntegral | IsUnsigned,
}, {
defined: Decimal,
expected: 18,
Expand Down
2 changes: 1 addition & 1 deletion go/sqltypes/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (v Value) IsFractional() (ok bool) {
return ok
}

// IsString returns true if Value a string, or needs
// IsString returns true if Value is a string, or needs
// to be quoted before sending to MySQL.
func (v Value) IsString() (ok bool) {
if v.Inner != nil {
Expand Down
24 changes: 12 additions & 12 deletions go/vt/proto/query/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go/vt/tabletserver/endtoend/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func TestFractionals(t *testing.T) {
sqltypes.Int32,
sqltypes.Decimal,
sqltypes.Decimal,
sqltypes.Float,
sqltypes.Double,
sqltypes.Float32,
sqltypes.Float64,
}
for i, field := range qr.Fields {
got, err := sqltypes.MySQLToType(field.Type, field.Flags)
Expand Down
8 changes: 4 additions & 4 deletions go/vt/tabletserver/proto/proto3.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ func buildValue(v interface{}) (pb.Value, error) {
}, nil
case float32:
return pb.Value{
Type: sqltypes.Double,
Type: sqltypes.Float64,
Value: strconv.AppendFloat(nil, float64(v), 'f', -1, 64),
}, nil
case float64:
return pb.Value{
Type: sqltypes.Double,
Type: sqltypes.Float64,
Value: strconv.AppendFloat(nil, v, 'f', -1, 64),
}, nil
case sqltypes.Value:
Expand All @@ -209,7 +209,7 @@ func buildValue(v interface{}) (pb.Value, error) {
case v.IsNumeric():
return pb.Value{Type: sqltypes.Int64, Value: v.Raw()}, nil
case v.IsFractional():
return pb.Value{Type: sqltypes.Double, Value: v.Raw()}, nil
return pb.Value{Type: sqltypes.Float64, Value: v.Raw()}, nil
}
return pb.Value{Type: sqltypes.VarBinary, Value: v.Raw()}, nil
case nil:
Expand Down Expand Up @@ -267,7 +267,7 @@ func buildSQLValue(v *pb.BindVariable) (interface{}, error) {
// TODO(sougou): Revisit this when QueryResult gets revamped
if v == nil || v.Type == sqltypes.Null {
return nil, nil
} else if int(v.Type)&sqltypes.IsNumber != 0 {
} else if int(v.Type)&sqltypes.IsIntegral != 0 {
if int(v.Type)&sqltypes.IsUnsigned != 0 {
return strconv.ParseUint(string(v.Value), 0, 64)
}
Expand Down
12 changes: 6 additions & 6 deletions proto/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message VTGateCallerID {
// Flag allows us to qualify types by their common properties.
enum Flag {
NONE = 0;
ISNUMBER = 256;
ISINTEGRAL = 256;
ISUNSIGNED = 512;
ISFLOAT = 1024;
ISQUOTED = 2048;
Expand Down Expand Up @@ -76,12 +76,12 @@ enum Type {
// UINT64 specifies a BIGINT UNSIGNED type.
// Properties: 10, IsNumber, IsUnsigned.
UINT64 = 778;
// FLOAT specifies a FLOAT type.
// FLOAT32 specifies a FLOAT type.
// Properties: 11, IsFloat.
FLOAT = 1035;
// DOUBLE specifies a DOUBLE or REAL type.
FLOAT32 = 1035;
// FLOAT64 specifies a DOUBLE or REAL type.
// Properties: 12, IsFloat.
DOUBLE = 1036;
FLOAT64 = 1036;
// TIMESTAMP specifies a TIMESTAMP type.
// Properties: 13, IsQuoted.
TIMESTAMP = 2061;
Expand Down Expand Up @@ -169,7 +169,7 @@ message Field {
// Row is a database row.
message Row {
// lengths contains the length of each value in values.
// A length of -1 means that that fields is NULL. While
// A length of -1 means that the field is NULL. While
// reading values, you have to accummulate the length
// to know the offset where the next value begins in values.
repeated sint64 lengths = 1;
Expand Down
Loading

0 comments on commit 94eb00f

Please sign in to comment.