From 4ae5b0d3813d55f743f7e2928999c098c416b506 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Tue, 26 Dec 2023 18:25:51 +0100 Subject: [PATCH 1/2] evalengine: Fix week overflow (#14859) Signed-off-by: Manan Gupta --- go/mysql/datetime/datetime.go | 8 ++++++++ go/vt/vtgate/evalengine/compiler_test.go | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/go/mysql/datetime/datetime.go b/go/mysql/datetime/datetime.go index cc1fc92e091..73ae234e932 100644 --- a/go/mysql/datetime/datetime.go +++ b/go/mysql/datetime/datetime.go @@ -315,12 +315,16 @@ func (d Date) Week(mode int) int { year, week := d.SundayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 1: year, week := d.ISOWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 2: @@ -333,12 +337,16 @@ func (d Date) Week(mode int) int { year, week := d.Sunday4DayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 5: year, week := d.MondayWeek() if year < d.Year() { return 0 + } else if year > d.Year() { + return 53 } return week case 6: diff --git a/go/vt/vtgate/evalengine/compiler_test.go b/go/vt/vtgate/evalengine/compiler_test.go index 06dd679920e..468d4737828 100644 --- a/go/vt/vtgate/evalengine/compiler_test.go +++ b/go/vt/vtgate/evalengine/compiler_test.go @@ -487,6 +487,22 @@ func TestCompilerSingle(t *testing.T) { expression: `case when null is null then 23 else null end`, result: `INT64(23)`, }, + { + expression: `week('2023-12-31', 4)`, + result: `INT64(53)`, + }, + { + expression: `week('2023-12-31', 2)`, + result: `INT64(53)`, + }, + { + expression: `week('2024-12-31', 1)`, + result: `INT64(53)`, + }, + { + expression: `week('2024-12-31', 5)`, + result: `INT64(53)`, + }, } for _, tc := range testCases { From 5e6cd8659025e07552680d1f1c4c5ff912a13af2 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Wed, 27 Dec 2023 15:39:47 +0530 Subject: [PATCH 2/2] test: fix upgrade-downgrade tests Signed-off-by: Manan Gupta --- go/test/endtoend/reparent/plannedreparent/reparent_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/test/endtoend/reparent/plannedreparent/reparent_test.go b/go/test/endtoend/reparent/plannedreparent/reparent_test.go index f7afea1431b..45cbeb565c7 100644 --- a/go/test/endtoend/reparent/plannedreparent/reparent_test.go +++ b/go/test/endtoend/reparent/plannedreparent/reparent_test.go @@ -295,7 +295,7 @@ func TestReparentWithDownReplica(t *testing.T) { // insert data into the new primary, check the connected replica work insertVal = utils.ConfirmReplication(t, tablets[1], []*cluster.Vttablet{tablets[0], tablets[3]}) } else { - assert.Contains(t, out, fmt.Sprintf("TabletManager.PrimaryStatus on %s error", tablets[2].Alias)) + assert.Contains(t, out, fmt.Sprintf("TabletManager.PrimaryStatus on %s", tablets[2].Alias)) // insert data into the old primary, check the connected replica works. The primary tablet shouldn't have changed. insertVal = utils.ConfirmReplication(t, tablets[0], []*cluster.Vttablet{tablets[1], tablets[3]}) }