-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: fix TIMESTAMP func get wrong result with decimal (#15185) #20088
Conversation
/run-all-tests |
/run-all-tests |
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
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.
…#15185) The TIMESTAMP function deal with argument of decimal/float will get wrong result. This commit fix that issue by redirect method call of parseDateTime() to ParseDatetimeFromNum() when the flag "isFloat" is true. The reason is that the parse logic of datetime is different when dealing with strings and numbers. In short, when dealing with numbers, if number length are not 6, 8, 12, 14, the parse logic should padded with leading zeros to the closest length. But when dealing with strings, the parse logic will interpreted from left to right to find year, month, day, hour... for as many parts as are present in the string. For more details, see https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html.
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
/merge |
/run-all-tests |
@LENSHOOD merge failed. |
/run-integration-copr-test |
@LENSHOOD It's work for |
/merge |
/run-all-tests |
@ti-srebot /run-all-tests |
Got it. Thx! |
/run-integration-copr-test tikv=pr/8737 |
/reward 300 |
You are not the mentor for the linked issue. |
/run-all-tests tikv=pr/8737 |
/reward 300 |
Reward success. |
@ti-srebot /run-all-tests tikv=pr/8737 |
/run-all-tests tikv=pr/8737 |
tics test is not working for |
Thx, so is this PR need to manually merge due to the tests are not fully passed? (cannot use /merge command) |
/run-all-tests tikv=pr/8737
Thx, so is this PR need to manually merge due to the tests are not fully passed? (cannot use command) |
Yes. Now it need |
/run-all-tests |
@LENSHOOD, Congratulations, you get 300 in this PR, and your total score is 300 in high-performance challenge program. |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-3.0 in PR #20469 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #20470 |
What problem does this PR solve?
Issue Number: close #15185
Problem Summary:
The TIMESTAMP function deal with argument of decimal/float will get wrong result.
e.g.:
Run sql :
SELECT TIMESTAMP(11111.1111);
Expected:
2001-11-11 00:00:00.0000
Actual:
2011-11-01 11:11:00.0000
The reason is that the parse logic of
datetime
is different when dealing with strings and numbers.In short, when dealing with numbers, if number length are not 6, 8, 12, 14, the parse logic should padded with leading zeros to the closest length.
When dealing with strings, the parse logic will interpreted from left to right to find year, month, day, hour... for as many parts as are present in the string.
For more details, see
https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html.
https://github.com/mysql/mysql-server/blob/5.7/sql-common/my_time.c
What is changed and how it works?
What's Changed:
The original code treat strings and numbers as all the same.
To spilt that logic, I redirect method call of parseDateTime() to ParseDatetimeFromNum() when the flag "isFloat" is true.
Check List
Tests
Release note