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

expression : fix function 'binSearch' in builtinIntervalRealSig not return error #12957

Merged
merged 9 commits into from
Nov 27, 2019
Merged
2 changes: 1 addition & 1 deletion expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ func (b *builtinIntervalRealSig) binSearch(target float64, args []Expression, ro
for i < j {
mid := i + (j-i)/2
v, isNull, err1 := args[mid].EvalReal(b.ctx, row)
if err != nil {
if err1 != nil {
err = err1
break
}
Expand Down
48 changes: 28 additions & 20 deletions expression/builtin_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,33 +214,41 @@ func (s *testEvaluatorSuite) TestIntervalFunc(c *C) {
}()

for _, t := range []struct {
args []types.Datum
ret int64
args []types.Datum
ret int64
getErr bool
}{
{types.MakeDatums(nil, 1, 2), -1},
{types.MakeDatums(1, 2, 3), 0},
{types.MakeDatums(2, 1, 3), 1},
{types.MakeDatums(3, 1, 2), 2},
{types.MakeDatums(0, "b", "1", "2"), 1},
{types.MakeDatums("a", "b", "1", "2"), 1},
{types.MakeDatums(23, 1, 23, 23, 23, 30, 44, 200), 4},
gtygo marked this conversation as resolved.
Show resolved Hide resolved
{types.MakeDatums(23, 1.7, 15.3, 23.1, 30, 44, 200), 2},
{types.MakeDatums(9007199254740992, 9007199254740993), 0},
{types.MakeDatums(uint64(9223372036854775808), uint64(9223372036854775809)), 0},
{types.MakeDatums(9223372036854775807, uint64(9223372036854775808)), 0},
{types.MakeDatums(-9223372036854775807, uint64(9223372036854775808)), 0},
{types.MakeDatums(uint64(9223372036854775806), 9223372036854775807), 0},
{types.MakeDatums(uint64(9223372036854775806), -9223372036854775807), 1},
{types.MakeDatums("9007199254740991", "9007199254740992"), 0},
{types.MakeDatums(nil, 1, 2), -1, false},
{types.MakeDatums(1, 2, 3), 0, false},
{types.MakeDatums(2, 1, 3), 1, false},
{types.MakeDatums(3, 1, 2), 2, false},
{types.MakeDatums(0, "b", "1", "2"), 1, false},
{types.MakeDatums("a", "b", "1", "2"), 1, false},
{types.MakeDatums(23, 1, 23, 23, 23, 30, 44, 200), 4, false},
{types.MakeDatums(23, 1.7, 15.3, 23.1, 30, 44, 200), 2, false},
{types.MakeDatums(9007199254740992, 9007199254740993), 0, false},
{types.MakeDatums(uint64(9223372036854775808), uint64(9223372036854775809)), 0, false},
{types.MakeDatums(9223372036854775807, uint64(9223372036854775808)), 0, false},
{types.MakeDatums(-9223372036854775807, uint64(9223372036854775808)), 0, false},
{types.MakeDatums(uint64(9223372036854775806), 9223372036854775807), 0, false},
{types.MakeDatums(uint64(9223372036854775806), -9223372036854775807), 1, false},
{types.MakeDatums("9007199254740991", "9007199254740992"), 0, false},
{types.MakeDatums(1, uint32(1), uint32(1)), 0, true},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why will this return an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This testcase will cover (SF * scalarfunction) evalreal , and it will return an error: cannot convert 1 (type uint32) to string


// tests for appropriate precision loss
{types.MakeDatums(9007199254740992, "9007199254740993"), 1},
{types.MakeDatums("9007199254740992", 9007199254740993), 1},
{types.MakeDatums("9007199254740992", "9007199254740993"), 1},
{types.MakeDatums(9007199254740992, "9007199254740993"), 1, false},
{types.MakeDatums("9007199254740992", 9007199254740993), 1, false},
{types.MakeDatums("9007199254740992", "9007199254740993"), 1, false},
} {
fc := funcs[ast.Interval]
f, err := fc.getFunction(s.ctx, s.datumsToConstants(t.args))
c.Assert(err, IsNil)
if t.getErr {
v, err := evalBuiltinFunc(f, chunk.Row{})
c.Assert(err, NotNil)
c.Assert(v.GetInt64(), Equals, t.ret)
continue
}
v, err := evalBuiltinFunc(f, chunk.Row{})
c.Assert(err, IsNil)
c.Assert(v.GetInt64(), Equals, t.ret)
Expand Down