Skip to content

Commit

Permalink
[release-18.0] evalengine: Fix week overflow (#14859) (#14861)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
Co-authored-by: Dirkjan Bussink <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
  • Loading branch information
3 people authored Dec 27, 2023
1 parent 142a074 commit 770f16e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions go/mysql/datetime/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/reparent/plannedreparent/reparent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]})
}
Expand Down
16 changes: 16 additions & 0 deletions go/vt/vtgate/evalengine/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 770f16e

Please sign in to comment.