Skip to content

Commit

Permalink
*: fixed a mistake whileing adding sqrt math func (pingcap#2513)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhexuany authored and coocood committed Jan 19, 2017
1 parent 2123638 commit 30f97af
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ var funcs = map[string]functionClass{
ast.Rand: &randFunctionClass{baseFunctionClass{ast.Rand, 0, 1}},
ast.Round: &roundFunctionClass{baseFunctionClass{ast.Round, 1, 2}},
ast.Sign: &signFunctionClass{baseFunctionClass{ast.Sign, 1, 1}},
ast.Sqrt: &sqrtFunctionClass{baseFunctionClass{ast.Sqrt, 1, 1}},
ast.Conv: &convFunctionClass{baseFunctionClass{ast.Conv, 3, 3}},
ast.CRC32: &crc32FunctionClass{baseFunctionClass{ast.CRC32, 1, 1}},

Expand Down
2 changes: 1 addition & 1 deletion expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ type sqrtFunctionClass struct {
}

func (c *sqrtFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) {
return &builtinSignSig{newBaseBuiltinFunc(args, ctx)}, errors.Trace(c.verifyArgs(args))
return &builtinSqrtSig{newBaseBuiltinFunc(args, ctx)}, errors.Trace(c.verifyArgs(args))
}

type builtinSqrtSig struct {
Expand Down
5 changes: 4 additions & 1 deletion expression/builtin_math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ func (s *testEvaluatorSuite) TestSqrt(c *C) {
Dtbl := tblToDtbl(tbl)

for _, t := range Dtbl {
v, err := builtinSqrt(t["Arg"], s.ctx)
fc := funcs[ast.Sqrt]
f, err := fc.getFunction(datumsToConstants(t["Arg"]), s.ctx)
c.Assert(err, IsNil)
v, err := f.eval(nil)
c.Assert(err, IsNil)
c.Assert(v, DeepEquals, t["Ret"][0], Commentf("arg:%v", t["Arg"]))
}
Expand Down

0 comments on commit 30f97af

Please sign in to comment.