-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
types: support %X %V %W formats for STR_TO_DATE() #21887
base: master
Are you sure you want to change the base?
Conversation
@tiancaiamao it's a critical bug that produces incorrect result, could you file an issue first? |
It's a tiny tiny bug fix for an ONCALL issue long long time ago. |
func yearOfWeekX(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 4) | ||
if !succ { | ||
return input, false | ||
} | ||
t.setYear(uint16(v)) | ||
ctx["X"] = 1 | ||
return input[4:], true | ||
} | ||
|
||
func yearOfWeekx(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 4) | ||
if !succ { | ||
return input, false | ||
} | ||
t.setYear(uint16(v)) | ||
ctx["x"] = 1 | ||
return input[4:], true | ||
} | ||
|
||
func weekModeV(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 2) | ||
// v should be in [01, 53] | ||
if !succ || v <= 0 || v > 53 { | ||
return input, false | ||
} | ||
ctx["WeekNumber"] = v | ||
ctx["SundayFirst"] = 1 | ||
ctx["V"] = 1 | ||
return input[2:], true | ||
} | ||
|
||
func weekModeU(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 2) | ||
// v should be in [00, 53] | ||
if !succ || v < 0 || v > 53 { | ||
return input, false | ||
} | ||
ctx["WeekNumber"] = v | ||
ctx["SundayFirst"] = 1 | ||
ctx["U"] = 1 | ||
return input[2:], true | ||
} | ||
|
||
func weekModev(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 2) | ||
// v should be in [01, 53] | ||
if !succ || v <= 0 || v > 53 { | ||
return input, false | ||
} | ||
ctx["WeekNumber"] = v | ||
ctx["v"] = 1 | ||
return input[2:], true | ||
} | ||
|
||
func weekModeu(t *CoreTime, input string, ctx map[string]int) (string, bool) { | ||
v, succ := parseDigits(input, 2) | ||
// v should be in [00, 53] | ||
if !succ || v < 0 || v > 53 { | ||
return input, false | ||
} | ||
ctx["WeekNumber"] = v | ||
ctx["u"] = 1 | ||
return input[2:], true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that most of the codes are duplicates, can we simplify them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not duplicated.
Take a close look, you will find the tiny different between those functions. @wjhuang2016
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Can we take the difference as a parameter? Will it hurt the performance?
[FORMAT CHECKER NOTIFICATION] Notice: To remove the 📖 For more info, you can check the "Contribute Code" section in the development guide. |
@tiancaiamao: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
What problem does this PR solve?
MySQL:
TiDB:
Problem Summary:
%X %V %W
formats are not supportedWhat is changed and how it works?
What's Changed:
Support
%X %V %W
for STR_TO_DATE()How it Works:
It works the same with MySQL after this change.
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note
%X
%V
and%W
format for builtin functionSTR_TO_DATE()