From f996816eb74c3b03acd9ffb941f3b102710cc985 Mon Sep 17 00:00:00 2001 From: gtygo Date: Wed, 27 Nov 2019 13:59:56 +0800 Subject: [PATCH] expression : fix function 'binSearch' in builtinIntervalRealSig not return error (#12957) --- expression/builtin_compare.go | 2 +- expression/builtin_compare_test.go | 48 +++++++++++++++++------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index fbc6e30e4db1c..b91ab400334f7 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -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 } diff --git a/expression/builtin_compare_test.go b/expression/builtin_compare_test.go index 914f940c7ea7d..bd61ad8cca7aa 100644 --- a/expression/builtin_compare_test.go +++ b/expression/builtin_compare_test.go @@ -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}, - {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}, // 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)