expression: fix a bug when datum.kind is not consistent with expression.type (#4269)
This commit is contained in:
@ -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 <nil> 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)
|
||||
|
||||
@ -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("<nil>"))
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user