Skip to content

Commit

Permalink
Merge branch 'master' into coocood/fix-join-subquery
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut committed Apr 1, 2016
2 parents f8696d6 + 76388c2 commit 67cdbe2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
4 changes: 2 additions & 2 deletions evaluator/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func builtinNow(args []types.Datum, _ context.Context) (d types.Datum, err error
d.SetNull()
return d, errors.Trace(err)
}
d.SetMysqlTime(&tr)
d.SetMysqlTime(tr)
return d, nil
}

Expand Down Expand Up @@ -373,7 +373,7 @@ func builtinCurrentDate(args []types.Datum, _ context.Context) (d types.Datum, e
t := mysql.Time{
Time: time.Date(year, month, day, 0, 0, 0, 0, time.Local),
Type: mysql.TypeDate, Fsp: 0}
d.SetMysqlTime(&t)
d.SetMysqlTime(t)
return d, nil
}

Expand Down
12 changes: 3 additions & 9 deletions mysql/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,7 @@ func (t Time) ConvertToDuration() (Duration, error) {

// Compare returns an integer comparing the time instant t to o.
// If t is after o, return 1, equal o, return 0, before o, return -1.
func (t *Time) Compare(o *Time) int {
if o == nil {
return 1
}
func (t Time) Compare(o Time) int {
if t.Time.After(o.Time) {
return 1
} else if t.Time.Equal(o.Time) {
Expand All @@ -302,7 +299,7 @@ func (t Time) CompareString(str string) (int, error) {
return 0, errors.Trace(err)
}

return t.Compare(&o), nil
return t.Compare(o), nil
}

// RoundFrac rounds fractional seconds precision with new fsp and returns a new one.
Expand Down Expand Up @@ -1030,10 +1027,7 @@ func checkTimestamp(t Time) bool {
}

// ExtractTimeNum extracts time value number from time unit and format.
func ExtractTimeNum(unit string, t *Time) (int64, error) {
if t == nil {
return 0, errors.Errorf("invalid time t")
}
func ExtractTimeNum(unit string, t Time) (int64, error) {
switch strings.ToUpper(unit) {
case "MICROSECOND":
return int64(t.Nanosecond() / 1000), nil
Expand Down
2 changes: 1 addition & 1 deletion tidb-server/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func dumpRowValuesBinary(alloc arena.Allocator, columns []*ColumnInfo, row []typ
case types.KindMysqlDecimal:
data = append(data, dumpLengthEncodedString(hack.Slice(val.GetMysqlDecimal().String()), alloc)...)
case types.KindMysqlTime:
data = append(data, dumpBinaryDateTime(*val.GetMysqlTime(), nil)...)
data = append(data, dumpBinaryDateTime(val.GetMysqlTime(), nil)...)
case types.KindMysqlDuration:
data = append(data, dumpBinaryTime(val.GetMysqlDuration().Duration)...)
case types.KindMysqlSet:
Expand Down
19 changes: 7 additions & 12 deletions util/types/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ func (d *Datum) SetMysqlSet(b mysql.Set) {
}

// GetMysqlTime gets mysql.Time value
func (d *Datum) GetMysqlTime() *mysql.Time {
return d.x.(*mysql.Time)
func (d *Datum) GetMysqlTime() mysql.Time {
return d.x.(mysql.Time)
}

// SetMysqlTime sets mysql.Time value
func (d *Datum) SetMysqlTime(b *mysql.Time) {
func (d *Datum) SetMysqlTime(b mysql.Time) {
d.k = KindMysqlTime
d.x = b
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func (d *Datum) GetValue() interface{} {
case KindMysqlSet:
return d.GetMysqlSet()
case KindMysqlTime:
return *d.GetMysqlTime()
return d.GetMysqlTime()
default:
return d.GetInterface()
}
Expand Down Expand Up @@ -325,10 +325,8 @@ func (d *Datum) SetValue(val interface{}) {
d.SetMysqlHex(x)
case mysql.Set:
d.SetMysqlSet(x)
case *mysql.Time:
d.SetMysqlTime(x)
case mysql.Time:
d.SetMysqlTime(&x)
d.SetMysqlTime(x)
case []Datum:
d.SetRow(x)
case []interface{}:
Expand Down Expand Up @@ -477,7 +475,7 @@ func (d *Datum) compareString(s string) (int, error) {
return d.GetMysqlDecimal().Cmp(dec), err
case KindMysqlTime:
dt, err := mysql.ParseDatetime(s)
return d.GetMysqlTime().Compare(&dt), err
return d.GetMysqlTime().Compare(dt), err
case KindMysqlDuration:
dur, err := mysql.ParseDuration(s, mysql.MaxFsp)
return d.GetMysqlDuration().Compare(dur), err
Expand Down Expand Up @@ -563,10 +561,7 @@ func (d *Datum) compareMysqlSet(set mysql.Set) (int, error) {
}
}

func (d *Datum) compareMysqlTime(time *mysql.Time) (int, error) {
if time == nil {
return 0, errors.Errorf("invalid time t")
}
func (d *Datum) compareMysqlTime(time mysql.Time) (int, error) {
switch d.k {
case KindString, KindBytes:
dt, err := mysql.ParseDatetime(d.GetString())
Expand Down
2 changes: 1 addition & 1 deletion xapi/tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func unflatten(datum types.Datum, ft *types.FieldType) (types.Datum, error) {
if err != nil {
return datum, errors.Trace(err)
}
datum.SetMysqlTime(&t)
datum.SetMysqlTime(t)
return datum, nil
case mysql.TypeDuration:
dur := mysql.Duration{Duration: time.Duration(datum.GetInt64())}
Expand Down

0 comments on commit 67cdbe2

Please sign in to comment.