From 52c5443bf50004f2b68c9a8bfad5260b734b5be3 Mon Sep 17 00:00:00 2001 From: Tangruilin Date: Sun, 12 Dec 2021 19:30:43 +0800 Subject: [PATCH 1/3] fix #19150 --- expression/builtin_time.go | 8 ++++++++ expression/builtin_time_test.go | 1 + 2 files changed, 9 insertions(+) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 0c87fe8ec299c..f16b14676d173 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -20,6 +20,7 @@ package expression import ( "fmt" + "github.com/pingcap/tidb/util/parser" "math" "regexp" "strconv" @@ -5556,6 +5557,13 @@ func (b *builtinAddStringAndStringSig) evalString(row chunk.Row) (result string, } return "", true, err } + + check := arg1Str + _, check, _ = parser.Number(parser.Space0(check)) + check, err = parser.Char(check, '-') + if strings.Compare(check, "") != 0 && err == nil { + return "", true, nil + } if isDuration(arg0) { result, err = strDurationAddDuration(sc, arg0, arg1) if err != nil { diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 7e41e0c8c549d..76fe07e3ce571 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -939,6 +939,7 @@ func TestAddTimeSig(t *testing.T) { {"2018-08-16 20:21:01", "00:00:00.000001", "2018-08-16 20:21:01.000001"}, {"1", "xxcvadfgasd", ""}, {"xxcvadfgasd", "1", ""}, + {"2020-05-13 14:01:24", "2020-04-29 05:11:19", ""}, } fc := funcs[ast.AddTime] for _, c := range tbl { From 0de8e9a6bc0ed8bd6f62f510c0bedea41cc731be Mon Sep 17 00:00:00 2001 From: Tangruilin Date: Sun, 12 Dec 2021 20:52:34 +0800 Subject: [PATCH 2/3] fix #19150 --- expression/builtin_time.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index f16b14676d173..2b674e2b7d758 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -20,7 +20,6 @@ package expression import ( "fmt" - "github.com/pingcap/tidb/util/parser" "math" "regexp" "strconv" @@ -40,6 +39,7 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/logutil" + "github.com/pingcap/tidb/util/parser" "github.com/pingcap/tipb/go-tipb" "github.com/tikv/client-go/v2/oracle" "go.uber.org/zap" From 6d429d977f6f04f34c7ec91e7512fcbc432a897b Mon Sep 17 00:00:00 2001 From: Tangruilin Date: Thu, 16 Dec 2021 21:04:15 +0800 Subject: [PATCH 3/3] fix #19150 --- expression/builtin_time.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 2b674e2b7d758..cd17a2f829920 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -5559,11 +5559,14 @@ func (b *builtinAddStringAndStringSig) evalString(row chunk.Row) (result string, } check := arg1Str - _, check, _ = parser.Number(parser.Space0(check)) - check, err = parser.Char(check, '-') - if strings.Compare(check, "") != 0 && err == nil { - return "", true, nil + _, check, err = parser.Number(parser.Space0(check)) + if err == nil { + check, err = parser.Char(check, '-') + if strings.Compare(check, "") != 0 && err == nil { + return "", true, nil + } } + if isDuration(arg0) { result, err = strDurationAddDuration(sc, arg0, arg1) if err != nil {