evaluator: move the files in buildin package to evaluator package
Move the files in buildin package to evaluator package.
This commit is contained in:
@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"github.com/juju/errors"
|
||||
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"github.com/pingcap/tidb/context"
|
||||
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -19,7 +19,7 @@ import (
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
func (s *testBuiltinSuite) TestIf(c *C) {
|
||||
func (s *testEvaluatorSuite) TestIf(c *C) {
|
||||
tbl := []struct {
|
||||
Arg1 interface{}
|
||||
Arg2 interface{}
|
||||
@ -41,7 +41,7 @@ func (s *testBuiltinSuite) TestIf(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestIfNull(c *C) {
|
||||
func (s *testEvaluatorSuite) TestIfNull(c *C) {
|
||||
tbl := []struct {
|
||||
Arg1 interface{}
|
||||
Arg2 interface{}
|
||||
@ -59,7 +59,7 @@ func (s *testBuiltinSuite) TestIfNull(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestNullIf(c *C) {
|
||||
func (s *testEvaluatorSuite) TestNullIf(c *C) {
|
||||
tbl := []struct {
|
||||
Arg1 interface{}
|
||||
Arg2 interface{}
|
||||
@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"github.com/juju/errors"
|
||||
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
@ -21,12 +21,7 @@ import (
|
||||
"github.com/pingcap/tidb/util/mock"
|
||||
)
|
||||
|
||||
var _ = Suite(&testBuiltinInfoSuite{})
|
||||
|
||||
type testBuiltinInfoSuite struct {
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestDatabase(c *C) {
|
||||
func (s *testEvaluatorSuite) TestDatabase(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
v, err := builtinDatabase(nil, ctx)
|
||||
c.Assert(err, IsNil)
|
||||
@ -38,7 +33,7 @@ func (s *testBuiltinSuite) TestDatabase(c *C) {
|
||||
c.Assert(v, Equals, "test")
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestFoundRows(c *C) {
|
||||
func (s *testEvaluatorSuite) TestFoundRows(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
v, err := builtinFoundRows(nil, ctx)
|
||||
c.Assert(err, NotNil)
|
||||
@ -50,7 +45,7 @@ func (s *testBuiltinSuite) TestFoundRows(c *C) {
|
||||
c.Assert(v, Equals, uint64(0))
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestUser(c *C) {
|
||||
func (s *testEvaluatorSuite) TestUser(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
variable.BindSessionVars(ctx)
|
||||
sessionVars := variable.GetSessionVars(ctx)
|
||||
@ -61,7 +56,7 @@ func (s *testBuiltinSuite) TestUser(c *C) {
|
||||
c.Assert(v, Equals, "root@localhost")
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestCurrentUser(c *C) {
|
||||
func (s *testEvaluatorSuite) TestCurrentUser(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
variable.BindSessionVars(ctx)
|
||||
sessionVars := variable.GetSessionVars(ctx)
|
||||
@ -72,7 +67,7 @@ func (s *testBuiltinSuite) TestCurrentUser(c *C) {
|
||||
c.Assert(v, Equals, "root@localhost")
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestConnectionID(c *C) {
|
||||
func (s *testEvaluatorSuite) TestConnectionID(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
variable.BindSessionVars(ctx)
|
||||
sessionVars := variable.GetSessionVars(ctx)
|
||||
@ -83,7 +78,7 @@ func (s *testBuiltinSuite) TestConnectionID(c *C) {
|
||||
c.Assert(v, Equals, uint64(1))
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestVersion(c *C) {
|
||||
func (s *testEvaluatorSuite) TestVersion(c *C) {
|
||||
ctx := mock.NewContext()
|
||||
v, err := builtinVersion(nil, ctx)
|
||||
c.Assert(err, IsNil)
|
||||
@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"math"
|
||||
@ -11,13 +11,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
func (s *testBuiltinSuite) TestAbs(c *C) {
|
||||
func (s *testEvaluatorSuite) TestAbs(c *C) {
|
||||
tbl := []struct {
|
||||
Arg interface{}
|
||||
Ret interface{}
|
||||
@ -37,14 +37,14 @@ func (s *testBuiltinSuite) TestAbs(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestRand(c *C) {
|
||||
func (s *testEvaluatorSuite) TestRand(c *C) {
|
||||
v, err := builtinRand([]interface{}{}, nil)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(v, Less, float64(1))
|
||||
c.Assert(v, GreaterEqual, float64(0))
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestPow(c *C) {
|
||||
func (s *testEvaluatorSuite) TestPow(c *C) {
|
||||
tbl := []struct {
|
||||
Arg []interface{}
|
||||
Ret float64
|
||||
@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -22,7 +22,7 @@ import (
|
||||
"github.com/pingcap/tidb/mysql"
|
||||
)
|
||||
|
||||
func (s *testBuiltinSuite) TestLength(c *C) {
|
||||
func (s *testEvaluatorSuite) TestLength(c *C) {
|
||||
v, err := builtinLength([]interface{}{nil}, nil)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(v, IsNil)
|
||||
@ -47,7 +47,7 @@ func (s *testBuiltinSuite) TestLength(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestConcat(c *C) {
|
||||
func (s *testEvaluatorSuite) TestConcat(c *C) {
|
||||
args := []interface{}{nil}
|
||||
|
||||
v, err := builtinConcat(args, nil)
|
||||
@ -69,7 +69,7 @@ func (s *testBuiltinSuite) TestConcat(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestConcatWS(c *C) {
|
||||
func (s *testEvaluatorSuite) TestConcatWS(c *C) {
|
||||
args := []interface{}{nil}
|
||||
|
||||
v, err := builtinConcatWS(args, nil)
|
||||
@ -86,7 +86,7 @@ func (s *testBuiltinSuite) TestConcatWS(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestLeft(c *C) {
|
||||
func (s *testEvaluatorSuite) TestLeft(c *C) {
|
||||
args := []interface{}{"abcdefg", int64(2)}
|
||||
v, err := builtinLeft(args, nil)
|
||||
c.Assert(err, IsNil)
|
||||
@ -111,7 +111,7 @@ func (s *testBuiltinSuite) TestLeft(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestRepeat(c *C) {
|
||||
func (s *testEvaluatorSuite) TestRepeat(c *C) {
|
||||
args := []interface{}{"a", int64(2)}
|
||||
v, err := builtinRepeat(args, nil)
|
||||
c.Assert(err, IsNil)
|
||||
@ -138,7 +138,7 @@ func (s *testBuiltinSuite) TestRepeat(c *C) {
|
||||
c.Assert(v, Equals, "")
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestLowerAndUpper(c *C) {
|
||||
func (s *testEvaluatorSuite) TestLowerAndUpper(c *C) {
|
||||
v, err := builtinLower([]interface{}{nil}, nil)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(v, IsNil)
|
||||
@ -167,7 +167,7 @@ func (s *testBuiltinSuite) TestLowerAndUpper(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestStrcmp(c *C) {
|
||||
func (s *testEvaluatorSuite) TestStrcmp(c *C) {
|
||||
tbl := []struct {
|
||||
Input []interface{}
|
||||
Expect interface{}
|
||||
@ -194,7 +194,7 @@ func (s *testBuiltinSuite) TestStrcmp(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestReplace(c *C) {
|
||||
func (s *testEvaluatorSuite) TestReplace(c *C) {
|
||||
tbl := []struct {
|
||||
Input []interface{}
|
||||
Expect interface{}
|
||||
@ -11,24 +11,13 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/pingcap/check"
|
||||
)
|
||||
|
||||
func TestT(t *testing.T) {
|
||||
TestingT(t)
|
||||
}
|
||||
|
||||
var _ = Suite(&testBuiltinSuite{})
|
||||
|
||||
type testBuiltinSuite struct {
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestCoalesce(c *C) {
|
||||
func (s *testEvaluatorSuite) TestCoalesce(c *C) {
|
||||
args := []interface{}{1, nil}
|
||||
v, err := builtinCoalesce(args, nil)
|
||||
c.Assert(err, IsNil)
|
||||
@ -15,7 +15,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"time"
|
||||
@ -11,7 +11,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package builtin
|
||||
package evaluator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@ -21,7 +21,7 @@ import (
|
||||
"github.com/pingcap/tidb/mysql"
|
||||
)
|
||||
|
||||
func (s *testBuiltinSuite) TestDate(c *C) {
|
||||
func (s *testEvaluatorSuite) TestDate(c *C) {
|
||||
tblDate := []struct {
|
||||
Input interface{}
|
||||
Expect interface{}
|
||||
@ -167,7 +167,7 @@ func (s *testBuiltinSuite) TestDate(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestClock(c *C) {
|
||||
func (s *testEvaluatorSuite) TestClock(c *C) {
|
||||
// test hour, minute, second, micro second
|
||||
|
||||
tbl := []struct {
|
||||
@ -237,7 +237,7 @@ func (s *testBuiltinSuite) TestClock(c *C) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestNow(c *C) {
|
||||
func (s *testEvaluatorSuite) TestNow(c *C) {
|
||||
v, err := builtinNow(nil, nil)
|
||||
c.Assert(err, IsNil)
|
||||
t, ok := v.(mysql.Time)
|
||||
@ -259,7 +259,7 @@ func (s *testBuiltinSuite) TestNow(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestSysDate(c *C) {
|
||||
func (s *testEvaluatorSuite) TestSysDate(c *C) {
|
||||
last := time.Now()
|
||||
v, err := builtinSysDate(nil, nil)
|
||||
c.Assert(err, IsNil)
|
||||
@ -277,7 +277,7 @@ func (s *testBuiltinSuite) TestSysDate(c *C) {
|
||||
c.Assert(err, NotNil)
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestCurrentDate(c *C) {
|
||||
func (s *testEvaluatorSuite) TestCurrentDate(c *C) {
|
||||
last := time.Now()
|
||||
v, err := builtinCurrentDate(nil, nil)
|
||||
c.Assert(err, IsNil)
|
||||
@ -286,7 +286,7 @@ func (s *testBuiltinSuite) TestCurrentDate(c *C) {
|
||||
c.Assert(n.String(), GreaterEqual, last.Format(mysql.DateFormat))
|
||||
}
|
||||
|
||||
func (s *testBuiltinSuite) TestCurrentTime(c *C) {
|
||||
func (s *testEvaluatorSuite) TestCurrentTime(c *C) {
|
||||
tfStr := "15:04:05"
|
||||
|
||||
last := time.Now()
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"github.com/juju/errors"
|
||||
"github.com/pingcap/tidb/ast"
|
||||
"github.com/pingcap/tidb/context"
|
||||
"github.com/pingcap/tidb/evaluator/builtin"
|
||||
"github.com/pingcap/tidb/mysql"
|
||||
"github.com/pingcap/tidb/parser/opcode"
|
||||
"github.com/pingcap/tidb/sessionctx/variable"
|
||||
@ -668,7 +667,7 @@ func (e *Evaluator) variable(v *ast.VariableExpr) bool {
|
||||
}
|
||||
|
||||
func (e *Evaluator) funcCall(v *ast.FuncCallExpr) bool {
|
||||
f, ok := builtin.Funcs[v.FnName.L]
|
||||
f, ok := Funcs[v.FnName.L]
|
||||
if !ok {
|
||||
e.err = ErrInvalidOperation.Gen("unknown function %s", v.FnName.O)
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user