From d5e54589d4a1243cf312308aa341ed9f3e0e69b6 Mon Sep 17 00:00:00 2001 From: jackyan Date: Mon, 26 Aug 2019 11:21:50 +0800 Subject: [PATCH] expression: give the full error message when the result of calling the exp function is out of range --- expression/builtin_math.go | 2 +- expression/integration_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/expression/builtin_math.go b/expression/builtin_math.go index 88d7c9c171170..db24c77015652 100644 --- a/expression/builtin_math.go +++ b/expression/builtin_math.go @@ -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 diff --git a/expression/integration_test.go b/expression/integration_test.go index 59bdae56242d7..285d1c5bf1b92 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -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);")