Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
  • Loading branch information
wjhuang2016 committed Mar 29, 2023
1 parent 59927c5 commit 866cacc
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 159 deletions.
10 changes: 0 additions & 10 deletions br/pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,7 @@ func ParseTSString(ts string) (uint64, error) {
sc := &stmtctx.StatementContext{
TimeZone: loc,
}
<<<<<<< HEAD
t, err := types.ParseTime(sc, ts, mysql.TypeTimestamp, types.MaxFsp)
=======
if tzCheck {
tzIdx, _, _, _, _ := types.GetTimezone(ts)
if tzIdx < 0 {
return 0, errors.Errorf("must set timezone when using datetime format ts, e.g. '2018-05-11 01:42:23+0800'")
}
}
t, err := types.ParseTime(sc, ts, mysql.TypeTimestamp, types.MaxFsp, nil)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
if err != nil {
return 0, errors.Trace(err)
}
Expand Down
5 changes: 0 additions & 5 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,13 +1092,8 @@ func getDefaultValue(ctx sessionctx.Context, col *table.Column, option *ast.Colu
// If the function call is ast.CurrentTimestamp, it needs to be continuously processed.
}

<<<<<<< HEAD
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime {
vd, err := expression.GetTimeValue(ctx, option.Expr, tp, fsp)
=======
if tp == mysql.TypeTimestamp || tp == mysql.TypeDatetime || tp == mysql.TypeDate {
vd, err := expression.GetTimeValue(ctx, option.Expr, tp, fsp, nil)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
value := vd.GetValue()
if err != nil {
return nil, false, dbterror.ErrInvalidDefaultValue.GenWithStackByArgs(col.Name.O)
Expand Down
49 changes: 2 additions & 47 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ func (b *builtinCastRealAsTimeSig) evalTime(row chunk.Row) (types.Time, bool, er
return types.ZeroTime, false, nil
}
sc := b.ctx.GetSessionVars().StmtCtx
res, err := types.ParseTime(sc, fv, b.tp.GetType(), b.tp.GetDecimal())
res, err := types.ParseTime(sc, fv, b.tp.GetType(), b.tp.GetDecimal(), nil)
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}
Expand Down Expand Up @@ -1729,57 +1729,12 @@ func (b *builtinCastJSONAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNu
if isNull || err != nil {
return res, isNull, err
}
<<<<<<< HEAD
s, err := val.Unquote()
if err != nil {
return res, false, err
=======

switch val.TypeCode {
case types.JSONTypeCodeDate, types.JSONTypeCodeDatetime, types.JSONTypeCodeTimestamp:
res = val.GetTime()
res.SetType(b.tp.GetType())
if b.tp.GetType() == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
res.SetCoreTime(types.FromDate(res.Year(), res.Month(), res.Day(), 0, 0, 0, 0))
}
return res, isNull, err
case types.JSONTypeCodeDuration:
duration := val.GetDuration()

sc := b.ctx.GetSessionVars().StmtCtx
ts, err := getStmtTimestamp(b.ctx)
if err != nil {
ts = gotime.Now()
}
res, err = duration.ConvertToTimeWithTimestamp(sc, b.tp.GetType(), ts)
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}
res, err = res.RoundFrac(sc, b.tp.GetDecimal())
return res, isNull, err
case types.JSONTypeCodeString:
s, err := val.Unquote()
if err != nil {
return res, false, err
}
sc := b.ctx.GetSessionVars().StmtCtx
res, err = types.ParseTime(sc, s, b.tp.GetType(), b.tp.GetDecimal(), nil)
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}
if b.tp.GetType() == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
res.SetCoreTime(types.FromDate(res.Year(), res.Month(), res.Day(), 0, 0, 0, 0))
}
return res, isNull, err
default:
err = types.ErrTruncatedWrongVal.GenWithStackByArgs(types.TypeStr(b.tp.GetType()), val.String())
return res, true, b.ctx.GetSessionVars().StmtCtx.HandleTruncate(err)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
}
sc := b.ctx.GetSessionVars().StmtCtx
res, err = types.ParseTime(sc, s, b.tp.GetType(), b.tp.GetDecimal())
res, err = types.ParseTime(sc, s, b.tp.GetType(), b.tp.GetDecimal(), nil)
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
}
Expand Down
54 changes: 2 additions & 52 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,58 +492,8 @@ func (b *builtinCastJSONAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
if err != nil {
return err
}
<<<<<<< HEAD
tm, err := types.ParseTime(stmtCtx, s, b.tp.GetType(), fsp)
tm, err := types.ParseTime(stmtCtx, s, b.tp.GetType(), fsp, nil)
if err != nil {
=======

switch val.TypeCode {
case types.JSONTypeCodeDate, types.JSONTypeCodeDatetime, types.JSONTypeCodeTimestamp:
tm := val.GetTime()
times[i] = tm
times[i].SetType(b.tp.GetType())
if b.tp.GetType() == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
times[i].SetCoreTime(types.FromDate(tm.Year(), tm.Month(), tm.Day(), 0, 0, 0, 0))
}
case types.JSONTypeCodeDuration:
duration := val.GetDuration()

sc := b.ctx.GetSessionVars().StmtCtx
tm, err := duration.ConvertToTimeWithTimestamp(sc, b.tp.GetType(), ts)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
continue
}
tm, err = tm.RoundFrac(stmtCtx, fsp)
if err != nil {
return err
}
times[i] = tm
case types.JSONTypeCodeString:
s, err := val.Unquote()
if err != nil {
return err
}
tm, err := types.ParseTime(stmtCtx, s, b.tp.GetType(), fsp, nil)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
continue
}
times[i] = tm
if b.tp.GetType() == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
times[i].SetCoreTime(types.FromDate(tm.Year(), tm.Month(), tm.Day(), 0, 0, 0, 0))
}
default:
err = types.ErrTruncatedWrongVal.GenWithStackByArgs(types.TypeStr(b.tp.GetType()), val.String())
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
}
Expand Down Expand Up @@ -589,7 +539,7 @@ func (b *builtinCastRealAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
times[i] = types.ZeroTime
continue
}
tm, err := types.ParseTime(stmt, fv, b.tp.GetType(), fsp)
tm, err := types.ParseTime(stmt, fv, b.tp.GetType(), fsp, nil)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
return err
Expand Down
25 changes: 0 additions & 25 deletions types/datum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestToBool(t *testing.T) {
testDatumToBool(t, NewBinaryLiteralFromUint(0, -1), 0)
testDatumToBool(t, Enum{Name: "a", Value: 1}, 1)
testDatumToBool(t, Set{Name: "a", Value: 1}, 1)
<<<<<<< HEAD
testDatumToBool(t, json.CreateBinary(int64(1)), 1)
testDatumToBool(t, json.CreateBinary(int64(0)), 0)
testDatumToBool(t, json.CreateBinary("0"), 1)
Expand All @@ -93,26 +92,7 @@ func TestToBool(t *testing.T) {
testDatumToBool(t, json.CreateBinary(true), 1)
testDatumToBool(t, json.CreateBinary(false), 1)
testDatumToBool(t, json.CreateBinary(""), 1)
t1, err := ParseTime(&stmtctx.StatementContext{TimeZone: time.UTC}, "2011-11-10 11:11:11.999999", mysql.TypeTimestamp, 6)
=======
testDatumToBool(t, CreateBinaryJSON(int64(1)), 1)
testDatumToBool(t, CreateBinaryJSON(int64(0)), 0)
testDatumToBool(t, CreateBinaryJSON("0"), 1)
testDatumToBool(t, CreateBinaryJSON("aaabbb"), 1)
testDatumToBool(t, CreateBinaryJSON(float64(0.0)), 0)
testDatumToBool(t, CreateBinaryJSON(float64(3.1415)), 1)
testDatumToBool(t, CreateBinaryJSON([]interface{}{int64(1), int64(2)}), 1)
testDatumToBool(t, CreateBinaryJSON(map[string]interface{}{"ke": "val"}), 1)
testDatumToBool(t, CreateBinaryJSON("0000-00-00 00:00:00"), 1)
testDatumToBool(t, CreateBinaryJSON("0778"), 1)
testDatumToBool(t, CreateBinaryJSON("0000"), 1)
testDatumToBool(t, CreateBinaryJSON(nil), 1)
testDatumToBool(t, CreateBinaryJSON([]interface{}{nil}), 1)
testDatumToBool(t, CreateBinaryJSON(true), 1)
testDatumToBool(t, CreateBinaryJSON(false), 1)
testDatumToBool(t, CreateBinaryJSON(""), 1)
t1, err := ParseTime(&stmtctx.StatementContext{TimeZone: time.UTC}, "2011-11-10 11:11:11.999999", mysql.TypeTimestamp, 6, nil)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
require.NoError(t, err)
testDatumToBool(t, t1, 1)

Expand Down Expand Up @@ -244,14 +224,9 @@ func TestConvertToFloat(t *testing.T) {
}
}

<<<<<<< HEAD
// mustParseTimeIntoDatum is similar to ParseTime but panic if any error occurs.
func mustParseTimeIntoDatum(s string, tp byte, fsp int) (d Datum) {
t, err := ParseTime(&stmtctx.StatementContext{TimeZone: time.UTC}, s, tp, fsp)
=======
func mustParseTime(s string, tp byte, fsp int) Time {
t, err := ParseTime(&stmtctx.StatementContext{TimeZone: time.UTC}, s, tp, fsp, nil)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
if err != nil {
panic("ParseTime fail")
}
Expand Down
21 changes: 1 addition & 20 deletions types/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2035,20 +2035,6 @@ func TestParseWithTimezone(t *testing.T) {
}
}

<<<<<<< HEAD
=======
func TestMarshalTime(t *testing.T) {
sc := mock.NewContext().GetSessionVars().StmtCtx
v1, err := types.ParseTime(sc, "2017-01-18 01:01:01.123456", mysql.TypeDatetime, types.MaxFsp, nil)
require.NoError(t, err)
j, err := json.Marshal(v1)
require.NoError(t, err)
var v2 types.Time
require.NoError(t, json.Unmarshal(j, &v2))
require.Equal(t, 0, v1.Compare(v2))
}

>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
func BenchmarkFormat(b *testing.B) {
t1 := types.NewTime(types.FromGoTime(time.Now()), mysql.TypeTimestamp, 0)
for i := 0; i < b.N; i++ {
Expand All @@ -2063,13 +2049,8 @@ func BenchmarkTimeAdd(b *testing.B) {
sc := &stmtctx.StatementContext{
TimeZone: time.UTC,
}
<<<<<<< HEAD
arg1, _ := types.ParseTime(sc, "2017-01-18", mysql.TypeDatetime, types.MaxFsp)
arg2, _ := types.ParseDuration(sc, "12:30:59", types.MaxFsp)
=======
arg1, _ := types.ParseTime(sc, "2017-01-18", mysql.TypeDatetime, types.MaxFsp, nil)
arg2, _, _ := types.ParseDuration(sc, "12:30:59", types.MaxFsp)
>>>>>>> 8398f0fe098 (*: fix a timezone data race which may cause wrong row data (#41146))
arg2, _ := types.ParseDuration(sc, "12:30:59", types.MaxFsp)
for i := 0; i < b.N; i++ {
_, err := arg1.Add(sc, arg2)
if err != nil {
Expand Down

0 comments on commit 866cacc

Please sign in to comment.