-
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: Timestamp literal with time zone offset #57845
base: master
Are you sure you want to change the base?
Conversation
Hi @mjonss. 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 #57845 +/- ##
================================================
+ Coverage 72.8126% 73.4654% +0.6528%
================================================
Files 1677 1689 +12
Lines 463954 477205 +13251
================================================
+ Hits 337817 350581 +12764
- Misses 105277 105554 +277
- Partials 20860 21070 +210
Flags with carried forward coverage won't be shown. Click here to find out more.
|
// (regardless if min/sec exists or not...) | ||
`(\.\d*)?` + | ||
// Optionally time zone offset, must be +/-HH:MM format | ||
`([+-]\d{2}[:]\d{2})?` + |
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.
MySQL has this part very strict. It is more strict than what types.ParseTime parses the same string, so I think we should be more strict here as well, to avoid the situation where customer starts to use a more relaxed syntax, and we need to make it more strict.
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.
Yes, I agree with that
// Hour is mandatory | ||
// Any number of leading zeroes | ||
// 1-2 Hour digits | ||
`0*\d{1,2}` + |
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 is a fix to allow SELECT TIMESTAMP '2024-01-01 18'
// Any non-digit separator before Minute and Second parts | ||
// Any number of leading zeroes in Min/Sec! | ||
// 1-2 digit minutes/seconds | ||
`([^\d]0*\d{1,2}){0,2}` + |
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.
Another fix for allowing SELECT TIMESTAMP '2024-01-01 18[:00]'
. SELECT TIMESTAMP '2024-01-01 18:00:00'
did already work.
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.
Should it also accept this with the ODBC syntax?
mysql-8.0.11-TiDB-v8.5.0-alpha-219-gecd70f4222> SELECT { ts '2024-01-01 14:00:00-14:00' };
+------------------------------------+
| { ts '2024-01-01 14:00:00-14:00' } |
+------------------------------------+
| 2024-01-02 05:00:00 |
+------------------------------------+
1 row in set (0.00 sec)
Note that the MySQL behavior here is interesting:
mysql-9.1.0> SELECT { ts '2024-01-01 14:00:00+00:00' };
+------------------------------------+
| { ts '2024-01-01 14:00:00+00:00' } |
+------------------------------------+
| 2024-01-01 14:00:00 |
+------------------------------------+
1 row in set (0.00 sec)
mysql-9.1.0> SELECT { ts '2024-01-01 14:00:00-00:00' };
+---------------------------+
| 2024-01-01 14:00:00-00:00 |
+---------------------------+
| 2024-01-01 14:00:00-00:00 |
+---------------------------+
1 row in set (0.00 sec)
mysql-9.1.0> SELECT { ts '2024-01-01 14:00:00+01:00' };
+------------------------------------+
| { ts '2024-01-01 14:00:00+01:00' } |
+------------------------------------+
| 2024-01-01 13:00:00 |
+------------------------------------+
1 row in set (0.00 sec)
mysql-9.1.0> SELECT { ts '2024-01-01 14:00:00-01:00' };
+------------------------------------+
| { ts '2024-01-01 14:00:00-01:00' } |
+------------------------------------+
| 2024-01-01 15:00:00 |
+------------------------------------+
1 row in set (0.00 sec)
@@ -67,7 +67,34 @@ var ( | |||
durationPattern = regexp.MustCompile(`^\s*[-]?(((\d{1,2}\s+)?0*\d{0,3}(:0*\d{1,2}){0,2})|(\d{1,7}))?(\.\d*)?\s*$`) | |||
|
|||
// timestampPattern checks whether a string matches the format of timestamp. | |||
timestampPattern = regexp.MustCompile(`^\s*0*\d{1,4}([^\d]0*\d{1,2}){2}\s+(0*\d{0,2}([^\d]0*\d{1,2}){2})?(\.\d*)?\s*$`) | |||
timestampPattern = regexp.MustCompile(`^` + |
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 commented multi line regexp is a big improvement!
// (regardless if min/sec exists or not...) | ||
`(\.\d*)?` + | ||
// Optionally time zone offset, must be +/-HH:MM format | ||
`([+-]\d{2}[:]\d{2})?` + |
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.
Yes, I agree with that
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dveeden The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
@dveeden I thinks this is due to MySQL falls back to string literal for ODBC syntax, in case it is not a proper timestamp literal:
|
What problem does this PR solve?
Issue Number: close #51742
Problem Summary:
timestamp literal, like
TIMESTAMP '2024-11-29 19:20:21'
did not allow time zone offset, likeTIMESTAMP '2024-11-29 19:20:21+08:00'
What changed and how does it work?
Adjusted the internal regex limiting allowed patterns for TIMESTAMP literals.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.