Permalink
Browse files

expression: return NULL when error is not nil (#4749)

  • Loading branch information...
zz-jason authored and winoros committed Oct 11, 2017
1 parent c0bc20a commit 83ace4f748018857a365b64aed59bb3cf6116bd0
@@ -621,7 +621,7 @@ func (s *builtinArithmeticIntDivideIntSig) evalInt(row []types.Datum) (int64, bo
ret, err = types.DivInt64(a, b)
}
return ret, false, errors.Trace(err)
return ret, err != nil, errors.Trace(err)
}
func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row []types.Datum) (int64, bool, error) {
@@ -648,7 +648,7 @@ func (s *builtinArithmeticIntDivideDecimalSig) evalInt(row []types.Datum) (int64
ret, err := c.ToInt()
// err returned by ToInt may be ErrTruncated or ErrOverflow, only handle ErrOverflow, ignore ErrTruncated.
if err == types.ErrOverflow {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
return ret, false, nil
}
@@ -753,7 +753,7 @@ func (s *builtinArithmeticModDecimalSig) evalDecimal(row []types.Datum) (*types.
if err == types.ErrDivByZero {
return c, true, errors.Trace(handleDivisionByZeroError(s.ctx))
}
return c, false, errors.Trace(err)
return c, err != nil, errors.Trace(err)
}
type builtinArithmeticModIntSig struct {
@@ -1560,11 +1560,11 @@ func (s *builtinNullEQRealSig) evalInt(row []types.Datum) (val int64, isNull boo
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalReal(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalReal(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1586,11 +1586,11 @@ func (s *builtinNullEQDecimalSig) evalInt(row []types.Datum) (val int64, isNull
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalDecimal(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalDecimal(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1612,11 +1612,11 @@ func (s *builtinNullEQStringSig) evalInt(row []types.Datum) (val int64, isNull b
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalString(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalString(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1638,11 +1638,11 @@ func (s *builtinNullEQDurationSig) evalInt(row []types.Datum) (val int64, isNull
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalDuration(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalDuration(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1664,11 +1664,11 @@ func (s *builtinNullEQTimeSig) evalInt(row []types.Datum) (val int64, isNull boo
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalTime(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalTime(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1690,11 +1690,11 @@ func (s *builtinNullEQJSONSig) evalInt(row []types.Datum) (val int64, isNull boo
sc := s.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := s.args[0].EvalJSON(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := s.args[1].EvalJSON(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
var res int64
switch {
@@ -1705,7 +1705,7 @@ func (s *builtinNullEQJSONSig) evalInt(row []types.Datum) (val int64, isNull boo
default:
cmpRes, err := json.CompareJSON(arg0, arg1)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
if cmpRes == 0 {
res = 1
@@ -1853,7 +1853,7 @@ func compareDecimal(args []Expression, row []types.Datum, ctx context.Context) (
}
arg1, isNull1, err := args[1].EvalDecimal(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
if isNull1 || err != nil {
return 0, isNull1, errors.Trace(err)
@@ -1898,5 +1898,5 @@ func compareJSON(args []Expression, row []types.Datum, ctx context.Context) (int
return 0, isNull1, errors.Trace(err)
}
res, err := json.CompareJSON(arg0, arg1)
return int64(res), false, errors.Trace(err)
return int64(res), err != nil, errors.Trace(err)
}
@@ -371,7 +371,7 @@ func (b *builtinCaseWhenDurationSig) evalDuration(row []types.Datum) (ret types.
for i := 0; i < l-1; i += 2 {
condition, isNull, err = args[i].EvalInt(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
if isNull || condition == 0 {
continue
@@ -436,7 +436,7 @@ func (b *builtinIfIntSig) evalInt(row []types.Datum) (ret int64, isNull bool, er
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalInt(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -454,7 +454,7 @@ func (b *builtinIfRealSig) evalReal(row []types.Datum) (ret float64, isNull bool
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalReal(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -472,7 +472,7 @@ func (b *builtinIfDecimalSig) evalDecimal(row []types.Datum) (ret *types.MyDecim
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return nil, false, errors.Trace(err)
return nil, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalDecimal(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -490,7 +490,7 @@ func (b *builtinIfStringSig) evalString(row []types.Datum) (ret string, isNull b
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return "", false, errors.Trace(err)
return "", true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalString(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -508,7 +508,7 @@ func (b *builtinIfTimeSig) evalTime(row []types.Datum) (ret types.Time, isNull b
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalTime(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -526,7 +526,7 @@ func (b *builtinIfDurationSig) evalDuration(row []types.Datum) (ret types.Durati
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalDuration(row, sc)
if (!isNull0 && arg0 != 0) || err != nil {
@@ -544,15 +544,15 @@ func (b *builtinIfJSONSig) evalJSON(row []types.Datum) (ret json.JSON, isNull bo
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull0, err := b.args[0].EvalInt(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
arg1, isNull1, err := b.args[1].EvalJSON(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
arg2, isNull2, err := b.args[2].EvalJSON(row, sc)
if err != nil {
return ret, false, errors.Trace(err)
return ret, true, errors.Trace(err)
}
switch {
case isNull0 || arg0 == 0:
@@ -616,10 +616,10 @@ func (b *builtinIfNullIntSig) evalInt(row []types.Datum) (int64, bool, error) {
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalInt(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalInt(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullRealSig struct {
@@ -630,10 +630,10 @@ func (b *builtinIfNullRealSig) evalReal(row []types.Datum) (float64, bool, error
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalReal(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalReal(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullDecimalSig struct {
@@ -644,10 +644,10 @@ func (b *builtinIfNullDecimalSig) evalDecimal(row []types.Datum) (*types.MyDecim
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalDecimal(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalDecimal(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullStringSig struct {
@@ -658,10 +658,10 @@ func (b *builtinIfNullStringSig) evalString(row []types.Datum) (string, bool, er
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalString(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalString(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullTimeSig struct {
@@ -672,10 +672,10 @@ func (b *builtinIfNullTimeSig) evalTime(row []types.Datum) (types.Time, bool, er
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalTime(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalTime(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullDurationSig struct {
@@ -686,10 +686,10 @@ func (b *builtinIfNullDurationSig) evalDuration(row []types.Datum) (types.Durati
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalDuration(row, sc)
if !isNull || err != nil {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalDuration(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
type builtinIfNullJSONSig struct {
@@ -700,8 +700,8 @@ func (b *builtinIfNullJSONSig) evalJSON(row []types.Datum) (json.JSON, bool, err
sc := b.ctx.GetSessionVars().StmtCtx
arg0, isNull, err := b.args[0].EvalJSON(row, sc)
if !isNull {
return arg0, false, errors.Trace(err)
return arg0, err != nil, errors.Trace(err)
}
arg1, isNull, err := b.args[1].EvalJSON(row, sc)
return arg1, isNull, errors.Trace(err)
return arg1, isNull || err != nil, errors.Trace(err)
}
@@ -228,7 +228,7 @@ func (b *builtinPasswordSig) evalString(row []types.Datum) (d string, isNull boo
sc := b.ctx.GetSessionVars().StmtCtx
pass, isNull, err := b.args[0].EvalString(row, sc)
if isNull || err != nil {
return "", false, errors.Trace(err)
return "", err != nil, errors.Trace(err)
}
if len(pass) == 0 {
@@ -269,7 +269,7 @@ func (b *builtinRandomBytesSig) evalString(row []types.Datum) (string, bool, err
}
buf := make([]byte, len)
if n, err := rand.Read(buf); err != nil {
return "", false, errors.Trace(err)
return "", true, errors.Trace(err)
} else if int64(n) != len {
return "", false, errors.New("fail to generate random bytes")
}
@@ -178,7 +178,7 @@ func (b *builtinJSONUnquoteSig) evalString(row []types.Datum) (res string, isNul
return "", isNull, errors.Trace(err)
}
res, err = j.Unquote()
return res, false, errors.Trace(err)
return res, err != nil, errors.Trace(err)
}
type jsonSetFunctionClass struct {
@@ -217,10 +217,10 @@ func (b *builtinAbsDecSig) evalDecimal(row []types.Datum) (*types.MyDecimal, boo
*to = *val
} else {
if err = types.DecimalSub(new(types.MyDecimal), val, to); err != nil {
return nil, false, err
return nil, true, errors.Trace(err)
}
}
return to, false, errors.Trace(err)
return to, false, nil
}
func (c *roundFunctionClass) getFunction(ctx context.Context, args []Expression) (builtinFunc, error) {
@@ -306,9 +306,9 @@ func (b *builtinRoundDecSig) evalDecimal(row []types.Datum) (*types.MyDecimal, b
}
to := new(types.MyDecimal)
if err = val.Round(to, 0, types.ModeHalfEven); err != nil {
return nil, false, err
return nil, true, errors.Trace(err)
}
return to, false, errors.Trace(err)
return to, false, nil
}
type builtinRoundWithFracRealSig struct {
@@ -364,9 +364,9 @@ func (b *builtinRoundWithFracDecSig) evalDecimal(row []types.Datum) (*types.MyDe
}
to := new(types.MyDecimal)
if err = val.Round(to, int(frac), types.ModeHalfEven); err != nil {
return nil, false, err
return nil, true, errors.Trace(err)
}
return to, false, errors.Trace(err)
return to, false, nil
}
type ceilFunctionClass struct {
@@ -484,7 +484,7 @@ func (b *builtinCeilDecToDecSig) evalDecimal(row []types.Datum) (*types.MyDecima
if err != nil {
return nil, true, errors.Trace(err)
}
return res, false, errors.Trace(err)
return res, false, nil
}
type floorFunctionClass struct {
@@ -628,7 +628,7 @@ func (b *builtinFloorDecToDecSig) evalDecimal(row []types.Datum) (*types.MyDecim
if err != nil {
return nil, true, errors.Trace(err)
}
return res, false, errors.Trace(err)
return res, false, nil
}
type logFunctionClass struct {
@@ -811,7 +811,7 @@ type builtinRandWithSeedSig struct {
func (b *builtinRandWithSeedSig) evalReal(row []types.Datum) (float64, bool, error) {
seed, isNull, err := b.args[0].EvalInt(row, b.ctx.GetSessionVars().StmtCtx)
if err != nil {
return 0, false, errors.Trace(err)
return 0, true, errors.Trace(err)
}
if b.randGen == nil {
if isNull {
Oops, something went wrong.

0 comments on commit 83ace4f

Please sign in to comment.