-
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: fix getIntervalFromDecimal in DATE_ADD() #11297
Conversation
/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
expression/builtin_time.go
Outdated
@@ -2697,6 +2701,10 @@ func (du *baseDateArithmitical) getIntervalFromDecimal(ctx sessionctx.Context, a | |||
} | |||
} | |||
|
|||
if neg { | |||
interval = "-" + interval |
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 will be an incorrect result in case "SECOND"
and default
parts in the switch statement above.
4919bda
to
5cb495c
Compare
@SunRunAway PTAL |
Codecov Report
@@ Coverage Diff @@
## master #11297 +/- ##
===========================================
Coverage 81.6571% 81.6571%
===========================================
Files 423 423
Lines 91818 91818
===========================================
Hits 74976 74976
Misses 11531 11531
Partials 5311 5311 |
expression/builtin_time.go
Outdated
@@ -2684,19 +2688,25 @@ func (du *baseDateArithmitical) getIntervalFromDecimal(ctx sessionctx.Context, a | |||
/* keep interval as original decimal */ | |||
case "SECOND": | |||
// Decimal's EvalString is like %f format. | |||
neg = false |
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 would be better not to do the extra revise code in these paths.
Also, would you like to add a unit test to cover it?
/run-all-tests |
@SunRunAway PTAL |
cbf8901
to
ff0eb51
Compare
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.
LGTM
/run-all-tests |
e5a3e2b
to
34496d0
Compare
/run-all-tests |
cherry pick to release-2.1 failed |
cherry pick to release-3.0 in PR #11325 |
What problem does this PR solve?
#11286
Before this pr:
This pr:
What is changed and how it works?
When use
getIntervalFromDecimal
to get interval, It will convert the Decimal to Interval(the type is string).Before the pr, the func don't consider that the decimal may be a negative number. It get a wrong result.
e.g.
1 DAY_MICROSECOND
=>0 00:00:1
-2.2 DAY_MICROSECOND
=>0 00:00:-2.2
(wrong)This pr, before the converting, I judge whether the decimal is negative first.
-2.2 DAY_MICROSECOND
=>-0 00:00:2.2
Check List
Tests
Code changes
Side effects
Related changes