Skip to content
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

Fix evalEngine functions for dates on/before 0000-02-29 #15124

Merged
merged 9 commits into from
Feb 7, 2024

Conversation

beingnoble03
Copy link
Member

Description

This PR fixes evalEngine functions for dates on/before 0000-02-29, along with fixes for zero time in evalToTime.

Related Issue(s)

#15077

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Feb 2, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Feb 2, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Feb 2, 2024
Copy link

codecov bot commented Feb 2, 2024

Codecov Report

Attention: 137 lines in your changes are missing coverage. Please review.

Comparison is base (eddb39e) 47.29% compared to head (46e6b4c) 70.64%.
Report is 108 commits behind head on main.

Files Patch % Lines
go/vt/mysqlctl/builtinbackupengine.go 12.90% 54 Missing ⚠️
go/vt/mysqlctl/backupengine.go 0.00% 20 Missing ⚠️
go/vt/mysqlctl/xtrabackupengine.go 0.00% 15 Missing ⚠️
go/vt/schemadiff/column.go 70.83% 7 Missing ⚠️
go/mysql/conn.go 53.84% 6 Missing ⚠️
go/vt/mysqlctl/backup.go 37.50% 5 Missing ⚠️
go/mysql/capabilities/capability.go 91.48% 4 Missing ⚠️
go/mysql/query.go 77.77% 4 Missing ⚠️
go/vt/mysqlctl/schema.go 72.72% 3 Missing ⚠️
go/vt/schemadiff/schema.go 92.10% 3 Missing ⚠️
... and 11 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main   #15124       +/-   ##
===========================================
+ Coverage   47.29%   70.64%   +23.34%     
===========================================
  Files        1137     1376      +239     
  Lines      238684   182461    -56223     
===========================================
+ Hits       112895   128902    +16007     
+ Misses     117168    53559    -63609     
+ Partials     8621        0     -8621     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@systay systay added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Feb 5, 2024
func convertTz(dt datetime.DateTime, from, to *time.Location, now time.Time) (datetime.DateTime, bool) {
t := dt.ToStdTime(now)
lowerBoundTz := time.Date(1970, 01, 01, 0, 0, 0, 0, time.UTC)
upperBoundTz := time.Date(3001, 1, 19, 3, 14, 7, 99999, time.UTC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this based on https://dev.mysql.com/doc/dev/mysql-server/latest/my__time_8h.html#a67b86a393410bf1e9ab66ba46764c33d? It seems like it's slightly off from that value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a const maxUnixtime = 32536771200 which represents this value anyway. So I think we should use that. We also should add a date this far in the future then to the tests I think to ensure the max value is also tested (and not just pre-unix epoch times).

Copy link
Member Author

@beingnoble03 beingnoble03 Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://dev.mysql.com/doc/refman/8.3/en/date-and-time-functions.html#function_unix-timestamp

Says that for UNIX_TIMESTAMP is range is 1970-01-01 00:00:01.000000' UTC to '3001-01-19 03:14:07.999999' UTC (corresponding to 32536771199.999999 seconds).
[I checked, I think it should be 3001-01-18 23:59:59.999999 UTC, no idea why it says 3001-01-19 03:14:07.999999]

And,
https://dev.mysql.com/doc/refman/8.3/en/date-and-time-functions.html#function_convert-tz

Says that the range for CONVERT_TZ is '1970-01-01 00:00:01' UTC to '3001-01-18 23:59:59.999999' UTC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[I checked, I think it should be 3001-01-18 23:59:59.999999 UTC, no idea why it says 3001-01-19 03:14:07.999999]

Yeah, the docs are not always actually correct, the code speaks the truth usually 😄.

if t.Before(lowerBoundTz) || t.After(upperBoundTz) {
return dt, true
}

buf := datetime.DateTime_YYYY_MM_DD_hh_mm_ss.Format(dt, datetime.DefaultPrecision)
ts, err := time.ParseInLocation(time.DateTime, hack.String(buf), from)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already parsed it into a Go Time here. So the above conversion seems wasteful to me. I think what we can do is after we've done this parse, is check against the unix timestamp instead? So something like this instead which seems a lot simpler?

diff --git i/go/vt/vtgate/evalengine/fn_time.go w/go/vt/vtgate/evalengine/fn_time.go
index ecb1fedc13..ac1f03b589 100644
--- i/go/vt/vtgate/evalengine/fn_time.go
+++ w/go/vt/vtgate/evalengine/fn_time.go
@@ -341,6 +341,9 @@ func convertTz(dt datetime.DateTime, from, to *time.Location) (datetime.DateTime
        if err != nil {
                return datetime.DateTime{}, false
        }
+       if ts.Unix() < 0 || ts.Unix() >= maxUnixtime {
+               return dt, true
+       }
        return datetime.NewDateTimeFromStd(ts.In(to)), true
 }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The implementation was wrong here in my changes, MySQL checks the limit after converting. Moved the check at the end.

upperBoundTimestamp := time.Date(3001, 1, 19, 3, 14, 7, 99999, time.UTC)
if ts.Before(lowerBoundTimestamp) || ts.After(upperBoundTimestamp) {
return newEvalInt64(0)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I think testing against unix time stamps is much simpler here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

@dbussink dbussink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer now!

@frouioui frouioui modified the milestones: v19.0.0, v20.0.0 Feb 6, 2024
@vmg vmg merged commit 26c2e72 into vitessio:main Feb 7, 2024
102 checks passed
@vmg vmg added the Backport to: release-19.0 Needs to be back ported to release-19.0 label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport to: release-19.0 Needs to be back ported to release-19.0 Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants