Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix NAME_CONST function compatibility (#11241) #11268

Merged
merged 2 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4077,6 +4077,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;`)
Expand Down
7 changes: 6 additions & 1 deletion planner/core/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down