-
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
expression: Improve the compatibility of str_to_date
#25386
Conversation
Signed-off-by: JaySon-Huang <tshent@qq.com>
2da73c5
to
afc0923
Compare
Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
afc0923
to
a95a749
Compare
Signed-off-by: JaySon-Huang <tshent@qq.com>
result := oneOrTwoDigitRegex.FindString(input) // 1..12 | ||
length := len(result) | ||
hour, succ := parseDigits(input, length) |
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.
Can these lines extract a function?
I think extract a function like func parseOneOrTwoDigit(input string) (num int, succ bool, input string)
can increase the readability of the code
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.
Actually finding the length by oneOrTwoDigitRegex
is useless and costly, I combine them into one function in #25389 and improve the performance by about 50%.
I'd like to keep these code aligned with other parsing functions and will change them totally in that PR.
types/time.go
Outdated
if input = skipWhiteSpace(input); len(input) == 0 { | ||
return input, parseStateEndOfLine | ||
} |
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 think add skipWhiteSpace into parseSep when state is parseStateNormal is better. So the input can used by the next digit parse.
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.
And why need three states? I think fail or succ is enough..
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.
why need three states? I think fail or succ is enough..
Because MySQL accepts parsing some inputs like "11:13" with format "%r", which can be parsed into a datetime "11:13:00".
In parSep
, we may run into three situations:
- meet an ":", then we should accept it and continue to parse string left
- meet a char that is not ":", then we should stop the parsing and return a "ZeroTime"
- meet the end of the input string, then we should stop the parsing, with some parsing result
There are three different following actions, so we need three different states.
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.
add skipWhiteSpace into parseSep when state is parseStateNormal
Address
Signed-off-by: JaySon-Huang <tshent@qq.com>
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.
LGTM
@lzmhhh123 PTAL. plans to release it in v5.0.3 |
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 7955cde
|
/label needs-cherry-pick-5.1 |
/run-check_dev_2 |
Seems the failure is not related to the changes in this PR? |
/run-check_dev_2 |
/merge |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-5.0 in PR #25767 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-5.1 in PR #25768 |
What problem does this PR solve?
Issue Number: related to #24928
Problem Summary:
What is changed and how it works?
strings.EqualFold
for case insensitive prefix comparing infullNameMonth
abbreviatedMonth
case insensitivetime12Hour
andtime24Hour
accept some irregular inputsRelated changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note
str_to_date
for%b
/%M
/%r
/%T