-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
evalengine: Implement PERIOD_ADD
#16492
Conversation
Signed-off-by: Noble Mittal <[email protected]>
Signed-off-by: Noble Mittal <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16492 +/- ##
==========================================
+ Coverage 68.69% 68.75% +0.06%
==========================================
Files 1547 1556 +9
Lines 198297 199798 +1501
==========================================
+ Hits 136228 137380 +1152
- Misses 62069 62418 +349 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Noble Mittal <[email protected]>
go/vt/vtgate/evalengine/fn_time.go
Outdated
if !datetime.ValidatePeriod(period) { | ||
return nil, vterrors.NewErrorf(vtrpcpb.Code_INVALID_ARGUMENT, vterrors.WrongArguments, "Incorrect arguments to period_add") | ||
} | ||
return newEvalInt64(int64(datetime.MonthsToPeriod(datetime.PeriodToMonths(uint64(period)) + uint64(months)))), nil |
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.
this seems to be the only use of MonthsToPeriod
and PeriodToMonths
. Wouldn't it make sense to have it accept int64 in, and return int64 values? that way we wouldn't have to cast them here
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.
Yeah, not a huge issue but let's make it consistent so we don't cast here. @beingnoble03 Any reason it must be using an unsigned type?
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.
Done. If we want to avoid type-casting here, we would have to type-cast it in MonthsToPeriod
and PeriodToMonths
. Also, we'll using these functions for PERIOD_DIFF
, so this will avoid type-casting it there too.
@dbussink mysql-server
uses uint64
for these functions. Results would differ if we don't type-cast it into uint64
. (https://github.com/mysql/mysql-server/blob/trunk/mysys/my_time.cc#L2254)
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.
@dbussink
mysql-server
usesuint64
for these functions. Results would differ if we don't type-cast it intouint64
. (https://github.com/mysql/mysql-server/blob/trunk/mysys/my_time.cc#L2254)
I don't think that's very relevant here since those are values way out of bounds anyway?
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.
But months
can be negative here. So, we'll get different results for some negative cases e.g. PERIOD_ADD(1206, -1231232332)
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.
@dbussink We already run FnPeriodAdd
in cases.go
through some of these overflow cases (values in inputBitwise
in inputs.go
), which fail when we remove type-casting. Should we include more of these cases specifically in FnPeriodAdd
?
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.
@beingnoble03 I guess I'm confused how CI here passes then after the latest changes? Or are you talking about additional cleanups here?
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.
@dbussink I type casted it inside the function in the latest changes. That's why it's passing.
func PeriodToMonths(period int64) int64 {
p := uint64(period)
func MonthsToPeriod(months int64) int64 {
m := uint64(months)
The tests will fail, if this type casting is removed. I think I may have misunderstood. Did you mean something else?
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.
Ah yeah, that makes sense. I think we should cast it there where it makes most sense. If we also add PERIOD_DIFF
, were should we put it you think?
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.
@dbussink I think it will be best to type cast inside the function (the way it's done now). That would eliminate the need to type cast separately. I can create a PR for PERIOD_DIFF
once this is merged.
…dToMonths Signed-off-by: Noble Mittal <[email protected]>
Description
This PR adds implementation of
PERIOD_ADD
func in evalengine.Related Issue(s)
Checklist
Deployment Notes