Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: give the full error message when the result of calling the exp function is out of range #11862

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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