planner: fix NAME_CONST function compatibility (#11241)

This commit is contained in:
baishen
2019-07-16 11:15:54 +08:00
committed by Zhang Jian
parent 368119b8df
commit 7403ce331e
2 changed files with 10 additions and 1 deletions

View File

@ -4130,6 +4130,10 @@ func (s *testIntegrationSuite) TestFuncNameConst(c *C) {
r.Check(testkit.Rows("2"))
r = tk.MustQuery("SELECT concat('hello', name_const('test_string', 'world')) FROM t;")
r.Check(testkit.Rows("helloworld"))
r = tk.MustQuery("SELECT NAME_CONST('come', -1);")
r.Check(testkit.Rows("-1"))
r = tk.MustQuery("SELECT NAME_CONST('come', -1.0);")
r.Check(testkit.Rows("-1.0"))
err := tk.ExecToErr(`select name_const(a,b) from t;`)
c.Assert(err.Error(), Equals, "[planner:1210]Incorrect arguments to NAME_CONST")
err = tk.ExecToErr(`select name_const(a,"hello") from t;`)

View File

@ -178,7 +178,12 @@ func (p *preprocessor) Leave(in ast.Node) (out ast.Node, ok bool) {
p.err = expression.ErrIncorrectParameterCount.GenWithStackByArgs(x.FnName.L)
} else {
_, isValueExpr1 := x.Args[0].(*driver.ValueExpr)
_, isValueExpr2 := x.Args[1].(*driver.ValueExpr)
isValueExpr2 := false
switch x.Args[1].(type) {
case *driver.ValueExpr, *ast.UnaryOperationExpr:
isValueExpr2 = true
}
if !isValueExpr1 || !isValueExpr2 {
p.err = ErrWrongArguments.GenWithStackByArgs("NAME_CONST")
}