Skip to content

Commit

Permalink
expression: support NO_ZERO_DATE sql_mode (#16053)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Apr 22, 2020
1 parent a56b1aa commit db7c135
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 134 deletions.
14 changes: 7 additions & 7 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func (b *builtinCastIntAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNul
}
res, err = types.ParseTimeFromNum(b.ctx.GetSessionVars().StmtCtx, val, b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
Expand Down Expand Up @@ -841,7 +841,7 @@ func (b *builtinCastRealAsTimeSig) evalTime(row chunk.Row) (types.Time, bool, er
sc := b.ctx.GetSessionVars().StmtCtx
res, err := types.ParseTime(sc, fv, b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
Expand Down Expand Up @@ -1007,7 +1007,7 @@ func (b *builtinCastDecimalAsTimeSig) evalTime(row chunk.Row) (res types.Time, i
sc := b.ctx.GetSessionVars().StmtCtx
res, err = types.ParseTimeFromFloatString(sc, string(val.ToString()), b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func (b *builtinCastStringAsTimeSig) evalTime(row chunk.Row) (res types.Time, is
sc := b.ctx.GetSessionVars().StmtCtx
res, err = types.ParseTime(sc, val, b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
Expand Down Expand Up @@ -1277,7 +1277,7 @@ func (b *builtinCastTimeAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNu

sc := b.ctx.GetSessionVars().StmtCtx
if res, err = res.Convert(sc, b.tp.Tp); err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
res, err = res.RoundFrac(sc, int8(b.tp.Decimal))
if b.tp.Tp == mysql.TypeDate {
Expand Down Expand Up @@ -1544,7 +1544,7 @@ func (b *builtinCastDurationAsTimeSig) evalTime(row chunk.Row) (res types.Time,
sc := b.ctx.GetSessionVars().StmtCtx
res, err = val.ConvertToTime(sc, b.tp.Tp)
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
res, err = res.RoundFrac(sc, int8(b.tp.Decimal))
return res, false, err
Expand Down Expand Up @@ -1668,7 +1668,7 @@ func (b *builtinCastJSONAsTimeSig) evalTime(row chunk.Row) (res types.Time, isNu
sc := b.ctx.GetSessionVars().StmtCtx
res, err = types.ParseTime(sc, s, b.tp.Tp, int8(b.tp.Decimal))
if err != nil {
return types.ZeroTime, true, handleInvalidTimeError(b.ctx, err)
return types.ZeroTime, true, HandleInvalidTimeError(b.ctx, err)
}
if b.tp.Tp == mysql.TypeDate {
// Truncate hh:mm:ss part if the type is Date.
Expand Down
14 changes: 7 additions & 7 deletions expression/builtin_cast_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (b *builtinCastIntAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.
}
tm, err := types.ParseTimeFromNum(stmt, i64s[i], b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -482,7 +482,7 @@ func (b *builtinCastJSONAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
}
tm, err := types.ParseTime(stmtCtx, s, b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -524,7 +524,7 @@ func (b *builtinCastRealAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
}
tm, err := types.ParseTime(stmt, strconv.FormatFloat(f64s[i], 'f', -1, 64), b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -601,7 +601,7 @@ func (b *builtinCastDurationAsTimeSig) vecEvalTime(input *chunk.Chunk, result *c
duration.Fsp = fsp
tm, err := duration.ConvertToTime(stmtCtx, b.tp.Tp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -1360,7 +1360,7 @@ func (b *builtinCastDecimalAsTimeSig) vecEvalTime(input *chunk.Chunk, result *ch
}
tm, err := types.ParseTimeFromFloatString(stmt, string(decimals[i].ToString()), b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -1430,7 +1430,7 @@ func (b *builtinCastTimeAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk
}
res, err := times[i].Convert(stmt, b.tp.Tp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down Expand Up @@ -1636,7 +1636,7 @@ func (b *builtinCastStringAsTimeSig) vecEvalTime(input *chunk.Chunk, result *chu
}
tm, err := types.ParseTime(stmtCtx, buf.GetString(i), b.tp.Tp, fsp)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
result.SetNull(i, true)
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ func (b *builtinGreatestTimeSig) evalString(row chunk.Row) (_ string, isNull boo
}
t, err = types.ParseDatetime(sc, v)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return v, true, err
}
continue
Expand Down Expand Up @@ -800,7 +800,7 @@ func (b *builtinLeastTimeSig) evalString(row chunk.Row) (res string, isNull bool
}
t, err = types.ParseDatetime(sc, v)
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return v, true, err
} else if !findInvalidTime {
res = v
Expand Down
4 changes: 2 additions & 2 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func (b *builtinGreatestTimeSig) vecEvalString(input *chunk.Chunk, result *chunk
}
argTime, err = types.ParseDatetime(sc, result.GetString(i))
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
}
continue
Expand Down Expand Up @@ -739,7 +739,7 @@ func (b *builtinLeastTimeSig) vecEvalString(input *chunk.Chunk, result *chunk.Co
}
argTime, err = types.ParseDatetime(sc, result.GetString(i))
if err != nil {
if err = handleInvalidTimeError(b.ctx, err); err != nil {
if err = HandleInvalidTimeError(b.ctx, err); err != nil {
return err
} else if !findInvalidTime[i] {
invalidValue[i] = result.GetString(i)
Expand Down
Loading

0 comments on commit db7c135

Please sign in to comment.