From 249a494bbcd077b657a9eacf35ed9e5d1cf199da Mon Sep 17 00:00:00 2001 From: gtygo Date: Mon, 28 Oct 2019 12:02:21 +0800 Subject: [PATCH 1/3] fix : fix func binSearch not return error --- expression/builtin_compare.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index f19ba6d2c5536..00e7b4990ae9b 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -933,7 +933,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 } From e297a14959a89bcd6bb3361973e035e473c42f1e Mon Sep 17 00:00:00 2001 From: gtygo Date: Mon, 11 Nov 2019 21:04:56 +0800 Subject: [PATCH 2/3] add a test case for catch error --- expression/builtin_compare_test.go | 47 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/expression/builtin_compare_test.go b/expression/builtin_compare_test.go index 914f940c7ea7d..09ce27f853077 100644 --- a/expression/builtin_compare_test.go +++ b/expression/builtin_compare_test.go @@ -214,33 +214,40 @@ 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.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) From 4fc78348968531c2bb568bfef19abbcfaee0582c Mon Sep 17 00:00:00 2001 From: gtygo Date: Fri, 15 Nov 2019 12:26:51 +0800 Subject: [PATCH 3/3] update --- expression/builtin_compare_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/expression/builtin_compare_test.go b/expression/builtin_compare_test.go index 09ce27f853077..bd61ad8cca7aa 100644 --- a/expression/builtin_compare_test.go +++ b/expression/builtin_compare_test.go @@ -224,6 +224,7 @@ func (s *testEvaluatorSuite) TestIntervalFunc(c *C) { {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},