Skip to content

Commit

Permalink
expression: fix wrong behavior for IF(not_int, *, *) (pingcap#15016) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot committed Apr 15, 2020
1 parent ba735e9 commit 21a0586
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,10 @@ func (c *ifFunctionClass) getFunction(ctx sessionctx.Context, args []Expression)
}
retTp := InferType4ControlFuncs(args[1].GetType(), args[2].GetType())
evalTps := retTp.EvalType()
args[0], err = wrapWithIsTrue(ctx, true, args[0])
if err != nil {
return nil, err
}
bf := newBaseBuiltinFuncWithTp(ctx, args, evalTps, types.ETInt, evalTps, evalTps)
retTp.Flag |= bf.tp.Flag
bf.tp = retTp
Expand Down
6 changes: 6 additions & 0 deletions expression/builtin_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ func (s *testEvaluatorSuite) TestIf(c *C) {
{types.Duration{Duration: time.Duration(0)}, 1, 2, 2},
{types.NewDecFromStringForTest("1.2"), 1, 2, 1},
{jsonInt.GetMysqlJSON(), 1, 2, 1},
{0.1, 1, 2, 1},
{0.0, 1, 2, 2},
{types.NewDecFromStringForTest("0.1"), 1, 2, 1},
{types.NewDecFromStringForTest("0.0"), 1, 2, 2},
{"0.1", 1, 2, 1},
{"0.0", 1, 2, 2},
}

fc := funcs[ast.If]
Expand Down

0 comments on commit 21a0586

Please sign in to comment.