Skip to content

Commit

Permalink
expression: give the full error message when the result of calling th…
Browse files Browse the repository at this point in the history
…e exp function is out of range (#11862)
  • Loading branch information
Reminiscent authored and sre-bot committed Aug 27, 2019
1 parent d95a15e commit b438bf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ func (b *builtinExpSig) evalReal(row chunk.Row) (float64, bool, error) {
}
exp := math.Exp(val)
if math.IsInf(exp, 0) || math.IsNaN(exp) {
s := fmt.Sprintf("exp(%s)", strconv.FormatFloat(val, 'f', -1, 64))
s := fmt.Sprintf("exp(%s)", b.args[0].String())
return 0, false, types.ErrOverflow.GenWithStackByArgs("DOUBLE", s)
}
return exp, false, nil
Expand Down
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,17 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) {
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(rs.Close(), IsNil)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a float)")
tk.MustExec("insert into t values(1000000)")
rs, err = tk.Exec("select exp(a) from t")
c.Assert(err, IsNil)
_, err = session.GetRows4Test(ctx, tk.Se, rs)
c.Assert(err, NotNil)
terr = errors.Cause(err).(*terror.Error)
c.Assert(terr.Code(), Equals, terror.ErrCode(mysql.ErrDataOutOfRange))
c.Assert(err.Error(), Equals, "[types:1690]DOUBLE value is out of range in 'exp(test.t.a)'")
c.Assert(rs.Close(), IsNil)

// for conv
result = tk.MustQuery("SELECT CONV('a', 16, 2);")
Expand Down

0 comments on commit b438bf2

Please sign in to comment.