-
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: wrong result of timestampadd(month,1,date '2024-01-31') #53101
Conversation
Hi @xzhangxian1008. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. 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-sigs/prow repository. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #53101 +/- ##
================================================
+ Coverage 72.4215% 75.0256% +2.6040%
================================================
Files 1490 1493 +3
Lines 428984 438057 +9073
================================================
+ Hits 310677 328655 +17978
+ Misses 99041 89396 -9645
- Partials 19266 20006 +740
Flags with carried forward coverage won't be shown. Click here to find out more.
|
pkg/expression/builtin_time.go
Outdated
@@ -6232,6 +6232,11 @@ func addUnitToTime(unit string, t time.Time, v float64) (time.Time, bool, error) | |||
return tb, true, nil | |||
} | |||
tb = t.AddDate(0, int(v), 0) | |||
|
|||
// For corner case: timestampadd(month,1,date '2024-01-31') = "2024-02-29", timestampadd(month,1,date '2024-01-30') = "2024-02-29" | |||
for tb.Month() != t.Month()+1 { |
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.
What happen if adding more than 1 month?
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.
What happen if adding more than 1 month?
This is mysql: timestampadd(month,1,date '2024-01-31') = "2024-02-29"
This is tidb: timestampadd(month,1,date '2024-01-31') = "2024-03-02"
The month field of the result of timestampadd(month,1,date '2024-01-31')
is always 1 more than the month field of input. Adding more than 1 month is unexpected.
/cc @SeaRise |
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.
Others LGTM
@yibin87: adding LGTM is restricted to approvers and reviewers in OWNERS files. In response to this:
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. |
/cc @XuHuaiyu @windtalker |
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: windtalker, XuHuaiyu, yibin87 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
@@ -2580,6 +2580,18 @@ func TestTimestampAdd(t *testing.T) { | |||
{"MINUTE", 1.5, "1995-05-01 00:00:00", "1995-05-01 00:02:00"}, | |||
{"MINUTE", 1.5, "1995-05-01 00:00:00.000000", "1995-05-01 00:02:00"}, | |||
{"MICROSECOND", -100, "1995-05-01 00:00:00.0001", "1995-05-01 00:00:00"}, | |||
|
|||
// issue41052 | |||
{"MONTH", 1, "2024-01-31", "2024-02-29 00:00:00"}, |
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.
We should've at least had one case for negative month.
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.
We should've at least had one case for negative month.
fixed in #54916
What problem does this PR solve?
Issue Number: close #41052
Problem Summary:
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.