Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-17.0] evalengine: Fix week overflow (#14859) #14860

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go/mysql/datetime/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,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 @@ -332,12 +336,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
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 @@ -476,6 +476,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
Loading