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

type: add db prefix to function name for not exist error messages #11156

Merged
merged 8 commits into from
Sep 10, 2019
2 changes: 1 addition & 1 deletion executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (s *testSuite1) TestAggregation(c *C) {
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: stddev_pop")
_, err = tk.Exec("select std_samp(a) from t")
// TODO: Fix this error message.
c.Assert(errors.Cause(err).Error(), Equals, "[expression:1305]FUNCTION std_samp does not exist")
c.Assert(errors.Cause(err).Error(), Equals, "[expression:1305]FUNCTION test.std_samp does not exist")
_, err = tk.Exec("select variance(a) from t")
// TODO: Fix this error message.
c.Assert(errors.Cause(err).Error(), Equals, "unsupported agg function: var_pop")
Expand Down
20 changes: 20 additions & 0 deletions expression/integration_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4921,3 +4921,23 @@ func (s *testIntegrationSuite) TestIssue11309And11319(c *C) {
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 DAY_HOUR)`).Check(testkit.Rows("2007-03-31 00:08:28"))
tk.MustQuery(`SELECT DATE_ADD('2007-03-28 22:08:28',INTERVAL 2.2 YEAR_MONTH)`).Check(testkit.Rows("2009-05-28 22:08:28"))
}

func (s *testIntegrationSuite) TestNotExistFunc(c *C) {
tk := testkit.NewTestKit(c, s.store)

// current db is empty
_, err := tk.Exec("SELECT xxx(1)")
c.Assert(err.Error(), Equals, "[planner:1046]No database selected")

_, err = tk.Exec("SELECT yyy()")
c.Assert(err.Error(), Equals, "[planner:1046]No database selected")

// current db is not empty
tk.MustExec("use test")
_, err = tk.Exec("SELECT xxx(1)")
c.Assert(err.Error(), Equals, "[expression:1305]FUNCTION test.xxx does not exist")

_, err = tk.Exec("SELECT yyy()")
c.Assert(err.Error(), Equals, "[expression:1305]FUNCTION test.yyy does not exist")

}
7 changes: 6 additions & 1 deletion expression/scalar_function.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ func newFunctionImpl(ctx sessionctx.Context, fold bool, funcName string, retType
}
fc, ok := funcs[funcName]
if !ok {
return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", funcName)
db := ctx.GetSessionVars().CurrentDB
if db == "" {
return nil, terror.ClassOptimizer.New(mysql.ErrNoDB, mysql.MySQLErrName[mysql.ErrNoDB])
}
lizhenda marked this conversation as resolved.
Show resolved Hide resolved

return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", db+"."+funcName)
}
if !ctx.GetSessionVars().EnableNoopFuncs {
if _, ok := noopFuncs[funcName]; ok {
Expand Down
Empty file modified expression/scalar_function_test.go
100644 → 100755
Empty file.