From 024d4dde2016e549341b401038e35537c0f5e684 Mon Sep 17 00:00:00 2001 From: HuaiyuXu <391585975@qq.com> Date: Mon, 21 Aug 2017 20:38:46 +0800 Subject: [PATCH] expression: fix a bug when datum.kind is not consistent with expression.type (#4269) --- expression/expression.go | 6 ++++-- expression/integration_test.go | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/expression/expression.go b/expression/expression.go index e22cdb118d..a16f544abe 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -177,7 +177,9 @@ func evalExprToReal(expr Expression, row []types.Datum, sc *variable.StatementCo return res, val.IsNull(), errors.Trace(err) } if expr.GetTypeClass() == types.ClassReal { - return val.GetFloat64(), false, nil + // TODO: fix this to val.GetFloat64() after all built-in functions been rewritten. + res, err = val.ToFloat64(sc) + return res, false, errors.Trace(err) } else if IsHybridType(expr) { res, err = val.ToFloat64(sc) return res, false, errors.Trace(err) @@ -200,7 +202,7 @@ func evalExprToDecimal(expr Expression, row []types.Datum, sc *variable.Statemen // we infer the result type of the sql as `mysql.TypeNewDecimal` which is consistent with MySQL, // but what we actually get is store as float64 in Datum. // So if we wrap `CastDecimalAsInt` upon the result, we'll get when call `arg.EvalDecimal()`. - // This will be fixed after all built-in functions be rewrite correctlly. + // This will be fixed after all built-in functions be rewrite correctly. } else if IsHybridType(expr) { res, err = val.ToDecimal(sc) return res, false, errors.Trace(err) diff --git a/expression/integration_test.go b/expression/integration_test.go index cc7b91051a..325b960352 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -1525,6 +1525,8 @@ func (s *testIntegrationSuite) TestControlBuiltin(c *C) { result = tk.MustQuery("SELECT 79 + + + CASE -87 WHEN -30 THEN COALESCE(COUNT(*), +COALESCE(+15, -33, -12 ) + +72) WHEN +COALESCE(+AVG(DISTINCT(60)), 21) THEN NULL ELSE NULL END AS col0;") result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT -63 + COALESCE ( - 83, - 61 + - + 72 * - CAST( NULL AS SIGNED ) + + 3 );") + result.Check(testkit.Rows("-146")) } func (s *testIntegrationSuite) TestArithmeticBuiltin(c *C) {