From 3a9347ab10bc95652f81a33012a27d048f576e8a Mon Sep 17 00:00:00 2001 From: tangenta Date: Fri, 21 Jun 2024 16:49:19 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #54045 Signed-off-by: ti-chi-bot --- pkg/expression/helper.go | 17 +++++++++++++++-- tests/integrationtest/r/executor/write.result | 6 ++++++ tests/integrationtest/t/executor/write.test | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pkg/expression/helper.go b/pkg/expression/helper.go index 59d464f37a21b..0e2537ed9e584 100644 --- a/pkg/expression/helper.go +++ b/pkg/expression/helper.go @@ -92,14 +92,27 @@ func GetTimeValue(ctx BuildContext, v any, tp byte, fsp int, explicitTz *time.Lo switch x := v.(type) { case string: lowerX := strings.ToLower(x) +<<<<<<< HEAD if lowerX == ast.CurrentTimestamp || lowerX == ast.CurrentDate { if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { +======= + switch lowerX { + case ast.CurrentTimestamp: + if value, err = getTimeCurrentTimeStamp(ctx.GetEvalCtx(), tp, fsp); err != nil { +>>>>>>> 4d8e1d5e485 (expression: truncate time part for current_date columns (#54045)) return d, err } - } else if lowerX == types.ZeroDatetimeStr { + case ast.CurrentDate: + if value, err = getTimeCurrentTimeStamp(ctx.GetEvalCtx(), tp, fsp); err != nil { + return d, err + } + yy, mm, dd := value.Year(), value.Month(), value.Day() + truncated := types.FromDate(yy, mm, dd, 0, 0, 0, 0) + value.SetCoreTime(truncated) + case types.ZeroDatetimeStr: value, err = types.ParseTimeFromNum(tc, 0, tp, fsp) terror.Log(err) - } else { + default: value, err = types.ParseTime(tc, x, tp, fsp) if err != nil { return d, err diff --git a/tests/integrationtest/r/executor/write.result b/tests/integrationtest/r/executor/write.result index 2d8beea1b32d9..64356a3097d2a 100644 --- a/tests/integrationtest/r/executor/write.result +++ b/tests/integrationtest/r/executor/write.result @@ -2146,3 +2146,9 @@ Error 1364 (HY000): Field 'pk' doesn't have a default value replace t2 set c=default(a); Error 3105 (HY000): The value specified for generated column 'c' in table 't2' is not allowed. drop table t1, t2; +drop table if exists t; +create table t (a date default current_date); +insert into t values(); +select count(1) from t where a = date(a); +count(1) +1 diff --git a/tests/integrationtest/t/executor/write.test b/tests/integrationtest/t/executor/write.test index abea1af658bc4..3da9c50888acc 100644 --- a/tests/integrationtest/t/executor/write.test +++ b/tests/integrationtest/t/executor/write.test @@ -1350,3 +1350,8 @@ replace t2 set a=default(a), c=default(c); replace t2 set c=default(a); drop table t1, t2; +# TestIssue53746 +drop table if exists t; +create table t (a date default current_date); +insert into t values(); +select count(1) from t where a = date(a); From f87002c89e37238e144ec45ca47d4655f003690d Mon Sep 17 00:00:00 2001 From: tangenta Date: Fri, 2 Aug 2024 16:27:05 +0800 Subject: [PATCH 2/2] resolve conflict --- pkg/expression/helper.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pkg/expression/helper.go b/pkg/expression/helper.go index 0e2537ed9e584..02c392ed5feab 100644 --- a/pkg/expression/helper.go +++ b/pkg/expression/helper.go @@ -92,18 +92,13 @@ func GetTimeValue(ctx BuildContext, v any, tp byte, fsp int, explicitTz *time.Lo switch x := v.(type) { case string: lowerX := strings.ToLower(x) -<<<<<<< HEAD - if lowerX == ast.CurrentTimestamp || lowerX == ast.CurrentDate { - if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { -======= switch lowerX { case ast.CurrentTimestamp: - if value, err = getTimeCurrentTimeStamp(ctx.GetEvalCtx(), tp, fsp); err != nil { ->>>>>>> 4d8e1d5e485 (expression: truncate time part for current_date columns (#54045)) + if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { return d, err } case ast.CurrentDate: - if value, err = getTimeCurrentTimeStamp(ctx.GetEvalCtx(), tp, fsp); err != nil { + if value, err = getTimeCurrentTimeStamp(ctx, tp, fsp); err != nil { return d, err } yy, mm, dd := value.Year(), value.Month(), value.Day()