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) #12111

Merged
merged 4 commits into from
Sep 10, 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
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
Original file line number Diff line number Diff line change
Expand Up @@ -4781,3 +4781,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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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])
}

return nil, errFunctionNotExists.GenWithStackByArgs("FUNCTION", db+"."+funcName)
}
funcArgs := make([]Expression, len(args))
copy(funcArgs, args)
Expand Down